-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.config.js
127 lines (121 loc) · 2.76 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
const webpack = require('webpack');
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const WebpackShellPlugin = require('webpack-shell-plugin');
const isProduction = process.env.NODE_ENV === 'production';
const extractSass = new ExtractTextPlugin({
filename: "style.css"
});
const extractCss = new ExtractTextPlugin({
filename: "style.css"
})
const config = {
context: path.resolve(__dirname, './app'),
entry: {
vendor: [
'jquery',
'bootstrap-sass',
'moment',
'react',
'react-dom',
'react-router',
'react-router-dom',
'redux',
'react-redux',
'redux-saga'
],
main: './main.tsx'
},
output: {
path: path.resolve(__dirname, './dist'),
filename: '[name].js',
chunkFilename: '[name].chunk.js',
publicPath: '/'
},
resolve: {
extensions: ['.ts', '.tsx', '.js'],
alias: {
'app': path.resolve(__dirname, './app')
}
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: /(node_modules|bower_components)/,
},
{
test: /\.scss$/,
use: extractSass.extract({
use: [
{
loader: "css-loader"
},
{
loader: "sass-loader"
}
],
fallback: "style-loader"
})
},
{
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
loader: 'url-loader',
options: {
limit: 200000
}
},
{
test: require.resolve('./node_modules/jquery/dist/jquery.js'),
loader: 'expose-loader?$!expose-loader?jQuery'
}
]
},
plugins: [
new webpack.LoaderOptionsPlugin({
minimize: false,
options: {
context: __dirname
}
}),
extractSass,
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks(module, count) {
return module.resource && module.resource.indexOf('node_modules') !== -1
}
}),
new webpack.optimize.CommonsChunkPlugin({
children: true,
async: true,
minChunks: 3
})
]
}
if (isProduction) {
config.plugins.push(
new webpack.DefinePlugin({
'process.env': { NODE_ENV: JSON.stringify('production') }
})
);
config.plugins.push(
new webpack.optimize.UglifyJsPlugin({
parallel: true,
compress: { warnings: false },
output: {
comments: false
},
sourceMap: false
})
);
} else {
config.devtool = 'source-map';
config.plugins.push(
new WebpackShellPlugin({
onBuildStart:['echo "Webpack Start"', 'rm -rf dist'],
onBuildEnd:['echo "Webpack End"', 'node server.js']
})
);
}
module.exports = config;