-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
117 lines (109 loc) · 2.42 KB
/
webpack.config.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
const webpack = require('webpack');
const { merge } = require('webpack-merge');
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TARGET = process.env.npm_lifecycle_event;
const PATHS = {
app: path.join(__dirname, 'src'),
build: path.join(__dirname, 'build'),
};
process.env.BABEL_ENV = TARGET;
const common = {
entry: {
background: path.join(PATHS.app, 'background.js'),
flash: path.join(PATHS.app, 'flash.js'),
host: path.join(PATHS.app, 'host.js'),
injector: path.join(PATHS.app, 'injector.js'),
menu: path.join(PATHS.app, 'menu.js'),
},
resolve: {
extensions: ['.js', '.jsx'],
fallback: {
"url": false
}
},
output: {
chunkFilename: '[name].bundle.js',
path: PATHS.build,
filename: '[name].js',
publicPath: '/',
},
optimization: {
runtimeChunk: false,
},
module: {
rules: [
{
test: /\.jsx?$/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: TARGET === 'start',
compact: TARGET === 'build'
}
},
include: PATHS.app,
},
],
},
plugins: [
new CopyWebpackPlugin({
patterns: [
{ from: 'static' },
],
}),
new HtmlWebpackPlugin({
chunks: ['host'],
filename: 'host.html',
publicPath: './'
}),
],
};
const publicPath = `http://${process.env.HOST || 'localhost'}:${process.env.PORT || 8080}/`;
// Default configuration
if (TARGET === 'start' || !TARGET) {
module.exports = merge(common, {
devtool: false,
externals: [
'bindings',
],
mode: 'development',
output: {
publicPath,
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"development"',
})
],
});
}
if (TARGET === 'build' || TARGET === 'build:ci') {
module.exports = merge(common, {
devtool: 'source-map',
mode: 'production',
module: {
rules: [
{
test: /\.s?css$/,
use: [
'css-loader',
'sass-loader',
],
},
],
},
output: {
path: PATHS.build,
filename: '[name].js',
chunkFilename: '[name].js',
sourceMapFilename: '[name].js.map',
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"',
})
],
});
}