UNPKG

2.45 kBJavaScriptView Raw
1const webpack = require('webpack')
2const SWPrecachePlugin = require('sw-precache-webpack-plugin')
3const VueSSRClientPlugin = require('vue-server-renderer/client-plugin')
4const VueLoaderPlugin = require('vue-loader/lib/plugin')
5const CleanWebpackPlugin = require('clean-webpack-plugin')
6const CopyWebpackPlugin = require('copy-webpack-plugin')
7const ParallelUglifyPlugin = require('webpack-parallel-uglify-plugin')
8const ExtractTextPlugin = require('extract-text-webpack-plugin')
9const extractCSS = new ExtractTextPlugin({
10 filename: 'css/[name].css',
11 allChunks: true
12})
13
14const serverConfig = require('config').get('server')
15const pathConfig = require('config').get('path')
16
17const { isDevelopment, isProduction } = serverConfig
18
19const dllEntry = require('./dllEntry.js')
20
21const 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 // extractCSS,
42 // new CleanWebpackPlugin(
43 // ['dist/**/*.(js|css|json)', 'static/**/*.(js|css)'], // glob 匹配
44 // {
45 // root: pathConfig.root, // 根目录
46 // exclude: ['favicon.ico'], // 不包含
47 // verbose: true, // 开启输出
48 // dry: false // 启动删除文件
49 // }
50 // )
51]
52
53if (!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)'], // glob 匹配
67 {
68 root: pathConfig.root, // 根目录
69 exclude: ['favicon.ico'], // 不包含
70 verbose: true, // 开启输出
71 dry: false // 启动删除文件
72 }
73 )
74 ]
75 )
76}
77
78if (isProduction) {
79 plugins.push(
80 new ParallelUglifyPlugin({
81 uglifyJS: {
82 compress: {
83 warnings: false
84 }
85 }
86 })
87 )
88}
89
90module.exports = plugins