1 | const webpack = require('webpack')
|
2 | const SWPrecachePlugin = require('sw-precache-webpack-plugin')
|
3 | const VueSSRClientPlugin = require('vue-server-renderer/client-plugin')
|
4 | const VueLoaderPlugin = require('vue-loader/lib/plugin')
|
5 | const CleanWebpackPlugin = require('clean-webpack-plugin')
|
6 | const CopyWebpackPlugin = require('copy-webpack-plugin')
|
7 | const ParallelUglifyPlugin = require('webpack-parallel-uglify-plugin')
|
8 | const ExtractTextPlugin = require('extract-text-webpack-plugin')
|
9 | const extractCSS = new ExtractTextPlugin({
|
10 | filename: 'css/[name].css',
|
11 | allChunks: true
|
12 | })
|
13 |
|
14 | const serverConfig = require('config').get('server')
|
15 | const pathConfig = require('config').get('path')
|
16 |
|
17 | const { isDevelopment, isProduction } = serverConfig
|
18 |
|
19 | const dllEntry = require('./dllEntry.js')
|
20 |
|
21 | const plugins = [
|
22 | new VueLoaderPlugin(),
|
23 | new VueSSRClientPlugin(),
|
24 | new webpack.ProgressPlugin(),
|
25 | new webpack.EnvironmentPlugin(['NODE_ENV']),
|
26 | new webpack.DefinePlugin({
|
27 | 'process.env.NODE_ENV': '"production"',
|
28 | 'process.env.buildTime': JSON.stringify(Date.now())
|
29 | }),
|
30 | new webpack.ProvidePlugin({
|
31 | qs: 'query-string'
|
32 | }),
|
33 | new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
34 | new webpack.optimize.ModuleConcatenationPlugin(),
|
35 | ...Object.keys(dllEntry).map(
|
36 | v =>
|
37 | new webpack.DllReferencePlugin({
|
38 | manifest: require(`${pathConfig.dll}/${v}.json`)
|
39 | })
|
40 | )
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | ]
|
52 |
|
53 | if (!isDevelopment) {
|
54 | plugins.push(
|
55 | ...[
|
56 | new webpack.HotModuleReplacementPlugin(),
|
57 | new webpack.NoEmitOnErrorsPlugin(),
|
58 | new webpack.NamedModulesPlugin()
|
59 | ]
|
60 | )
|
61 | } else {
|
62 | plugins.push(
|
63 | ...[
|
64 | extractCSS,
|
65 | new CleanWebpackPlugin(
|
66 | ['dist/**/*.(js|css|json)', 'static/**/*.(js|css)'],
|
67 | {
|
68 | root: pathConfig.root,
|
69 | exclude: ['favicon.ico'],
|
70 | verbose: true,
|
71 | dry: false
|
72 | }
|
73 | )
|
74 | ]
|
75 | )
|
76 | }
|
77 |
|
78 | if (isProduction) {
|
79 | plugins.push(
|
80 | new ParallelUglifyPlugin({
|
81 | uglifyJS: {
|
82 | compress: {
|
83 | warnings: false
|
84 | }
|
85 | }
|
86 | })
|
87 | )
|
88 | }
|
89 |
|
90 | module.exports = plugins
|