-
Notifications
You must be signed in to change notification settings - Fork 51
/
webpack.config.js
86 lines (84 loc) · 2.08 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
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const path = require('path');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
.BundleAnalyzerPlugin;
const x = {
plugins: [
new CopyWebpackPlugin([
{ from: './src/assets', to: 'static' },
{ from: './thirdParty', to: 'thirdParty' },
{ from: './src/manifest.json' },
{ from: './src/js', to: 'js' },
{ from: './src/html' },
]),
],
entry: {
popup: ['babel-polyfill', './src/popup/popup.js'],
background: ['babel-polyfill', './src/background/index.js'],
imageSearch: ['babel-polyfill', './src/imageSearch/imageSearch.js'],
},
resolve: {
extensions: ['.webpack.js', '.js', '.jsx'],
alias: {
SRC: path.resolve(__dirname, 'src/'),
ASSET: path.resolve(__dirname, 'src/assets/'),
},
},
module: {
rules: [
{
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: [/node_modules/],
query: {
presets: [
'react',
[
'env',
{
targets: {
browsers: ['> 1%'],
},
},
],
],
plugins: [
'transform-es2015-destructuring',
'transform-es2015-parameters',
'transform-object-rest-spread',
],
},
},
{
test: /\.(png|jp(e*)g|svg|gif)$/,
use: [
{
loader: 'url-loader',
options: {
// Convert images < 8kb to base64 strings
name: 'images/[hash]-[name].[ext]',
},
},
],
},
],
},
output: {
path: path.resolve('dist'),
filename: 'js/[name].js',
},
};
module.exports = env => {
if (env === 'prod') {
x.optimization = {
minimizer: [new UglifyJsPlugin()],
};
} else if (env === 'preProd') {
x.plugins.push(new BundleAnalyzerPlugin());
} else {
x.devtool = 'source-map';
}
return x;
};