This repository has been archived by the owner on Jan 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.prod.js
76 lines (66 loc) · 1.82 KB
/
webpack.prod.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* @Author: zy9@github.com/zy410419243
* @Date: 2018-05-20 13:48:08
* @Last Modified by: zy9
* @Last Modified time: 2018-09-23 10:01:11
*/
const webpack = require('webpack');
const CleanWebpackPlugin = require('clean-webpack-plugin');
// const WebpackOnBuildPlugin = require('on-build-webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const TohoLogPlugin = require('toho-log-plugin');
const { commonModule, commonPlugin } = require('./webpack.common');
const dev = !!process.argv.includes('development');
let plugins = commonPlugin;
plugins.push(
new CopyWebpackPlugin([
{
from: __dirname + '/src/assets',
to: __dirname + '/dist/assets'
},
{
from: __dirname + '/manifest.json',
to: __dirname + '/dist',
force: true
},
{
from: __dirname + '/contentScript/css',
to: __dirname + '/dist/assets/contentScript'
}
])
);
plugins.push(new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/));
plugins.push(new TohoLogPlugin({ dev }));
dev && plugins.push(new CleanWebpackPlugin(['dist'], {
exclude: ['mainifest.json'], // 如果不加这个,在rebuild时,不会再复制json到dist中
verbose: false
}));
!dev && plugins.push(new CleanWebpackPlugin(['dist'], {
verbose: false
}));
const options = {
mode: dev ? 'development' : 'production',
// watch: dev,
devServer: {
port: 9099
},
resolve: {
extensions: ['.js', '.jsx'],
},
devtool: dev ? 'source-map' : '',
entry: {
background: __dirname + '/background',
contentScript: __dirname + '/contentScript',
main: __dirname + '/src',
inject: __dirname + '/inject'
},
output: {
path: __dirname + '/dist',
filename: '[name].js',
chunkFilename: dev ? 'main/vendor/[name].[chunkHash:8].js' : 'main/vendor/[name].js'
},
plugins,
module: commonModule
};
dev && webpack(options).watch({}, () => {});
!dev && webpack(options).run();