-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
72 lines (65 loc) · 1.5 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
const path = require('path')
const CleanPlugin = require('clean-webpack-plugin')
const plugins = ( () => {
const all = []
const production = [
new CleanPlugin('build'),
]
const dev = []
return all.concat(
process.env.NODE_ENV === 'production'
? production
: dev )
})()
const version = require('./package.json').version
module.exports = {
context: path.join(__dirname, 'src'),
entry: {
'background': './background',
'manifest': './manifest.json',
'img': './img/index',
},
plugins,
devtool: (process.env.NODE_ENV !== 'production') && 'source-map',
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'build'),
publicPath: '/',
},
module: {
rules: [
{ // add version from package.json to manifest
test: /manifest\.json$/,
use: [
'file-loader?name=manifest.json',
{
loader: 'str-replace-loader',
options: {
match: '{version}',
replace: version,
},
},
],
},
{ //copy image files
test: /\.png|svg|jpg|gif$/,
use: [
{
loader: 'file-loader',
options: {
name: '[path][name].[ext]',
useRelativePath: true,
},
},{
loader: 'image-webpack-loader',
options: {
optipng: {
optimizationLevel: 7,
},
},
},
],
},
],
},
}