-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
130 lines (119 loc) · 3.12 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
118
119
120
121
122
123
124
125
126
127
128
129
130
import Webpack from 'webpack';
import Path from 'path';
import Autoprefixer from 'autoprefixer';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import WriteFileWebpackPlugin from 'write-file-webpack-plugin';
import CircularDependencyPlugin from 'circular-dependency-plugin';
const PATH = {
ROOT: __dirname,
SOURCE: Path.join(__dirname, './src'),
TARGET: Path.join(__dirname, './dist')
};
const ENV = {
DEVELOPMENT: 'development',
PRODUCTION: 'production'
};
const NODE_ENV = process.env.NODE_ENV || ENV.DEVELOPMENT;
const Plugins = [
new Webpack.NamedModulesPlugin(),
new Webpack.optimize.ModuleConcatenationPlugin(),
new CircularDependencyPlugin({
// exclude detection of files based on a RegExp
exclude: /a\.js|node_modules/,
// add errors to webpack instead of warnings
failOnError: true
}),
new Webpack.optimize.CommonsChunkPlugin({async: true}),
new Webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify(NODE_ENV)
}
}),
new Webpack.EnvironmentPlugin({
NODE_ENV: NODE_ENV
})
];
if (NODE_ENV === ENV.PRODUCTION) {
Plugins.push(
new Webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}),
new Webpack.optimize.UglifyJsPlugin({
compress: {
conditionals: true,
comparisons: true,
sequences: true,
dead_code: true,
if_return: true,
join_vars: true,
screw_ie8: true,
warnings: false,
evaluate: true,
unused: true,
},
output: {
comments: false
}
})
);
}
const Loaders = [
{
test: /\.json$/,
loader: 'json-loader'
}, {
test: /\.ts$/,
loader: "awesome-typescript-loader"
}, {
test: /\.tsx$/,
loader: 'babel-loader',
query: {
presets: ['es2015', 'react']
}
}, {
test: /\.js$/,
loader: 'babel-loader',
exclude: /(node_modules)/,
query: {
presets: ['react', 'es2015', 'stage-0']
}
}, {
test: /.jsx$/,
loader: 'babel-loader',
exclude: /(node_modules)/,
query: {
presets: ['react', 'es2015', 'stage-0']
}
}
];
const WebpackConfig = {
context: PATH.TARGET,
node: {
fs: 'empty' // avoids error messages
},
output: {
filename: "js/[name].js"
},
resolve: {
extensions: ["", ".ts", ".tsx", ".js", ".jsx", ".json"],
modules: [
PATH.SOURCE,
Path.resolve(__dirname, 'node_modules')
],
alias: {
Core: Path.join(__dirname, 'src/Core'),
Popup: Path.join(__dirname, 'src/Popup'),
Background: Path.join(__dirname, 'src/Background')
}
},
devtool: 'inline-source-map',
plugins: Plugins,
module: {
loaders: Loaders
},
stats: {
children: false
}
};
export default WebpackConfig;