-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
75 lines (70 loc) · 1.96 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
const path = require('path');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const config = (env, argv) => {
function resolvePath(toResolve) {
return path.resolve(__dirname, toResolve);
}
const isProduction = argv.mode === 'production';
const buildPath = resolvePath('dist/');
const exclude = /(node_modules|dist)/;
const plugins = isProduction ? [] : [new webpack.HotModuleReplacementPlugin()];
return {
devtool: isProduction ? 'hidden-source-map' : 'cheap-module-source-map',
context: resolvePath('src'),
entry: {
content: path.join(__dirname, 'src', 'content', 'content.js'),
background: path.join(__dirname, 'src', 'background', 'background.js'),
options: path.join(__dirname, 'src', 'pages', 'options', 'options.js'),
},
module: {
rules: [
{
enforce: 'pre',
test: /\.js$/,
exclude,
loader: 'eslint-loader',
options: {
fix: true,
failOnError: isProduction,
},
},
{
exclude,
test: /\.js$/,
use: 'babel-loader',
},
{
test: /\.(png)$/,
use: ['file-loader'],
},
],
},
output: {
path: buildPath,
filename: '[name].js',
},
plugins: [
...plugins,
new webpack.DefinePlugin({
IS_PRODUCTION: JSON.stringify(isProduction),
}),
new CopyWebpackPlugin([
{ from: 'manifest.json', to: 'manifest.json' },
{ from: 'img/icon16.png', to: 'img/icon16.png' },
{ from: 'img/icon48.png', to: 'img/icon48.png' },
{ from: 'img/icon128.png', to: 'img/icon128.png' },
{ from: 'pages/options/index.html', to: 'options' },
]),
],
devServer: {
contentBase: buildPath,
host: '0.0.0.0',
port: 4000,
hot: true,
writeToDisk: true,
stats: 'minimal',
},
};
};
module.exports = config;