1. 程式人生 > >.Net Core應用框架Util介紹(三)

.Net Core應用框架Util介紹(三)

  1 const pathPlugin = require('path');
  2 const webpack = require('webpack');
  3 var Extract = require("extract-text-webpack-plugin");
  4 
  5 //第三方Js庫
  6 const jsModules = [
  7     'reflect-metadata',
  8     'zone.js',
  9     'moment',
 10     '@angular/animations',
 11     '@angular/common',
12 '@angular/common/http', 13 '@angular/compiler', 14 '@angular/core', 15 '@angular/forms', 16 '@angular/elements', 17 '@angular/platform-browser', 18 '@angular/platform-browser/animations', 19 '@angular/platform-browser-dynamic', 20 '@angular/router', 21 '@angular/cdk/esm5/collections.es5',
22 '@angular/flex-layout', 23 '@angular/material', 24 'primeng/primeng', 25 'lodash', 26 "echarts-ng2" 27 ]; 28 29 //第三方Css庫 30 const cssModules = [ 31 '@angular/material/prebuilt-themes/indigo-pink.css', 32 'material-design-icons/iconfont/material-icons.css',
33 'font-awesome/css/font-awesome.css', 34 'primeicons/primeicons.css', 35 'primeng/resources/themes/omega/theme.css', 36 'primeng/resources/primeng.min.css' 37 ]; 38 39 module.exports = (env) => { 40 //是否開發環境 41 const isDev = !(env && env.prod); 42 const mode = isDev ? "development" : "production"; 43 44 //將css提取到單獨檔案中 45 const extractCss = new Extract("vendor.css"); 46 47 //獲取路徑 48 function getPath(path) { 49 return pathPlugin.join(__dirname, path); 50 } 51 52 //打包第三方Js庫 53 let vendorJs = { 54 mode: mode, 55 entry: { vendor: jsModules }, 56 output: { 57 publicPath: 'dist/', 58 path: getPath("wwwroot/dist"), 59 filename: "[name].js", 60 library: '[name]' 61 }, 62 resolve: { 63 extensions: ['.js'] 64 }, 65 devtool: "source-map", 66 plugins: [ 67 new webpack.DllPlugin({ 68 path: getPath("wwwroot/dist/[name]-manifest.json"), 69 name: "[name]" 70 }), 71 new webpack.ContextReplacementPlugin(/\@angular\b.*\b(bundles|linker)/, getPath('./Typings')), 72 new webpack.ContextReplacementPlugin(/angular(\\|\/)core(\\|\/)@angular/, getPath('./Typings')), 73 new webpack.IgnorePlugin(/^vertx$/) 74 ] 75 } 76 77 //打包css 78 let vendorCss = { 79 mode: mode, 80 entry: { vendor: cssModules }, 81 output: { 82 publicPath: './', 83 path: getPath("wwwroot/dist"), 84 filename: "[name].css" 85 }, 86 devtool: "source-map", 87 module: { 88 rules: [ 89 { test: /\.css$/, use: extractCss.extract({ use: isDev ? 'css-loader' : 'css-loader?minimize' }) }, 90 { 91 test: /\.(png|jpg|gif|woff|woff2|eot|ttf|svg)(\?|$)/, use: { 92 loader: 'url-loader', 93 options: { 94 limit: 20000, 95 name: "[name].[ext]", 96 outputPath: "images/" 97 } 98 } 99 } 100 ] 101 }, 102 plugins: [ 103 extractCss 104 ] 105 } 106 return isDev ? [ vendorJs, vendorCss] : [vendorCss]; 107 }