1 | const pathConfig = require('config').get('path')
|
2 | const os = require('os')
|
3 | const path = require('path')
|
4 | const webpack = require('webpack')
|
5 | const CleanWebpackPlugin = require('clean-webpack-plugin')
|
6 | const AssetsWebpackPlugin = require('assets-webpack-plugin')
|
7 | const ParallelUglifyPlugin = require('webpack-parallel-uglify-plugin')
|
8 | const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
|
9 | const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
10 |
|
11 | const LIBRARY_NAME = '__[name]_[chunkhash]__'
|
12 | const entry = require('./dllEntry')
|
13 | const { NODE_ENV } = process.env
|
14 | const isProduction = NODE_ENV === 'production'
|
15 |
|
16 | const { publicPath } = require('./output.js')
|
17 |
|
18 | const webpackConfig = {
|
19 | node: false,
|
20 | mode: 'production',
|
21 | entry,
|
22 | output: {
|
23 | filename: `js/[name].[chunkhash].js`,
|
24 | path: pathConfig.dll,
|
25 | publicPath: publicPath,
|
26 | library: LIBRARY_NAME
|
27 | },
|
28 | resolve: {
|
29 | extensions: ['.js', '.css'],
|
30 | modules: [pathConfig.nodeModule]
|
31 | },
|
32 | resolveLoader: {
|
33 | modules: [pathConfig.nodeModule]
|
34 | },
|
35 | module: {
|
36 | rules: [
|
37 | {
|
38 | test: /\.css$/,
|
39 | use: [MiniCssExtractPlugin.loader, 'css-loader']
|
40 | },
|
41 | {
|
42 | test: /\.(png|jpe?g|gif|svg|woff2?|eot|ttf|otf)(\?.*)?$/,
|
43 | use: [
|
44 | {
|
45 | loader: 'url-loader',
|
46 | options: {
|
47 |
|
48 | limit: 10000,
|
49 | name: 'image/[name].[hash].[ext]'
|
50 | }
|
51 | }
|
52 | ]
|
53 | }
|
54 | ]
|
55 | },
|
56 | plugins: [
|
57 | new webpack.ProgressPlugin(),
|
58 | new webpack.EnvironmentPlugin(['NODE_ENV']),
|
59 | new CleanWebpackPlugin([pathConfig.dll], {
|
60 | root: pathConfig.root,
|
61 | verbose: false
|
62 | }),
|
63 | new MiniCssExtractPlugin({
|
64 | filename: 'css/[name].[contenthash].css'
|
65 | }),
|
66 | new webpack.DllPlugin({
|
67 | path: `${pathConfig.dll}/[name].json`,
|
68 | name: LIBRARY_NAME
|
69 | }),
|
70 | new AssetsWebpackPlugin({
|
71 | path: pathConfig.dll,
|
72 | filename: 'index.json',
|
73 | prettyPrint: true
|
74 | })
|
75 | ],
|
76 |
|
77 | optimization: {
|
78 | minimizer: [
|
79 | new ParallelUglifyPlugin({
|
80 | uglifyES: {
|
81 | compress: {
|
82 | warnings: true,
|
83 | drop_console: isProduction
|
84 | }
|
85 | },
|
86 | exclude: ['vendor.js'],
|
87 | sourceMap: false
|
88 | }),
|
89 | new OptimizeCssAssetsPlugin({
|
90 | assetNameRegExp: /\.css$/g,
|
91 | cssProcessor: require('cssnano'),
|
92 | cssProcessorPluginOptions: {
|
93 | preset: ['default', { discardComments: { removeAll: true } }]
|
94 | },
|
95 | canPrint: true
|
96 | })
|
97 | ]
|
98 | },
|
99 | stats: {
|
100 | colors: true,
|
101 | modules: false,
|
102 | children: false,
|
103 | chunks: false
|
104 | }
|
105 | }
|
106 |
|
107 | module.exports = { entry, webpackConfig }
|