-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
151 lines (121 loc) · 3.55 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
const path = require('path');
const webpack = require('webpack');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const srcRoot = path.resolve(__dirname, 'src');
const appRoot = path.resolve(srcRoot, 'app');
module.exports = (env) => {
const isDev = env == 'development';
return {
context: path.resolve(__dirname),
entry: {
main: './src/app/main.js',
vendor: [
'react', 'react-dom', 'jquery', 'moment',
// 'jquery-ui', 'bootstrap',
'react-bootstrap', 'lodash'
]
},
output: {
path: path.resolve(__dirname, './dist'),
filename: isDev ? 'js/[name].bundle.js' : 'js/[name].[hash].bundle.js',
sourceMapFilename: isDev ? 'js/[name].bundle.map' : 'js/[name].[chunkhash].bundle.map',
chunkFilename: isDev ? 'js/[id].chunk.js' : 'js/[id].[chunkhash].chunk.js',
publicPath: '/'
},
module: {
rules: [
{
test: /\.jsx?$/, // A regexp to test the require path. accepts either js or jsx
loader: 'babel-loader',
query:{
"presets": [
["es2015", {"modules": false}],
//Webpack understands the native import syntax, and uses it for tree shaking
"stage-2",
//Specifies what level of language features to activate.
//State 2 is "draft", 4 is finished, 0 is strawman.
//See https://tc39.github.io/process-document/
"react"
//Transpile React components to JS
],
"plugins": [
"react-hot-loader/babel"
//Enables React code to work with HMR.
]
},
exclude: [
/node_modules/,
],
},
{test: /\.css$/, loader: "style-loader!css-loader"},
{test: /\.json$/, loader: "json-loader"},
{
test: /\.(jpe?g|png|gif)$/,
loader: 'file-loader',
query:{
name: 'assets/img/[name].[ext]'
}
},
]
},
resolve: {
extensions: [".js", ".jsx"],
modules: [
appRoot,
'node_modules'
]
},
devServer: {
// historyApiFallback: true,
contentBase: path.join(__dirname, "dist"),
port: 2200,
// hot: true,
compress:true,
publicPath: '/',
stats: "minimal"
},
stats: "minimal",
performance: {
hints: false
},
devtool: isDev ? 'eval' : 'cheap-source-map', //false, //isDev ? 'eval' : 'cheap-source-map',
plugins: [
new CleanWebpackPlugin(['dist']),
new CopyWebpackPlugin([
{from: './src/index.html'},
{from: './src/assets', to: './assets'},
]),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new HtmlWebpackPlugin({
template: path.resolve(srcRoot, 'index.html'),
chunksSortMode: 'dependency'
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: 'js/[hash].vendor.js',
minChunks: Infinity,
}),
new webpack.DefinePlugin({
process: {
env: {
NODE_ENV: isDev ? '"development"' : '"production"'
}
}
}),
].concat(
!isDev
? // production only plugins
[
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}),
]
:// dev only plugins
[]
)
}
};