UNPKG

2.87 kBJavaScriptView Raw
1const pathConfig = require('config').get('path')
2const os = require('os')
3const path = require('path')
4const webpack = require('webpack')
5const CleanWebpackPlugin = require('clean-webpack-plugin')
6const AssetsWebpackPlugin = require('assets-webpack-plugin')
7const ParallelUglifyPlugin = require('webpack-parallel-uglify-plugin')
8const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
9const MiniCssExtractPlugin = require('mini-css-extract-plugin')
10// const extractCSS = require('./extract.js')
11const LIBRARY_NAME = '__[name]_[chunkhash]__'
12const entry = require('./dllEntry')
13const { NODE_ENV } = process.env
14const isProduction = NODE_ENV === 'production'
15
16const { publicPath } = require('./output.js')
17
18const 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 // 是否配置 static
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'), // 压缩和优化CSS 的处理器
92 cssProcessorPluginOptions: {
93 preset: ['default', { discardComments: { removeAll: true } }]
94 },
95 canPrint: true // 在 console 中打印信息
96 })
97 ]
98 },
99 stats: {
100 colors: true,
101 modules: false,
102 children: false,
103 chunks: false
104 }
105}
106
107module.exports = { entry, webpackConfig }