-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.babel.js
103 lines (88 loc) · 2.37 KB
/
webpack.config.babel.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
import webpack from 'webpack'
import CleanWebpackPlugin from 'clean-webpack-plugin'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import ExtractTextPlugin from 'extract-text-webpack-plugin'
import autoprefixer from 'autoprefixer'
import StyleExtHtmlWebpackPlugin from 'style-ext-html-webpack-plugin'
const env = process.env.NODE_ENV
const config = {}
const preloadCSS = new ExtractTextPlugin('bundle/preload.css')
const mainCSS = new ExtractTextPlugin('bundle/sif.[hash].css')
config.default = {
entry: {
sif: './src/',
},
output: {
path: './dist/',
publicPath: '/',
filename: 'bundle/[name].[hash].js',
},
module: {
loaders: [{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel',
}, {
test: /\.html?$/,
loader: 'html-loader?minimize=true&removeAttributeQuotes=false&interpolate=require',
}, {
test: /\.woff2?$/,
loader: 'url',
}, {
test: /preload\.scss$/,
loader: preloadCSS.extract(['css', 'postcss', 'sass']),
}, {
test: /sif\.scss$/,
loader: mainCSS.extract(['css', 'postcss', 'sass']),
}, {
test: /\.(jpe?g|png|gif|svg)$/i,
loaders: [
'url?limit=15000&name=assets/images/[name].[ext]',
'img',
]
}]
},
postcss: [
autoprefixer({ browsers: ['last 2 versions', 'ie 9-11'] }),
],
resolve: {
modulesDirectories: ['src', 'node_modules'],
extensions: ['', '.js', '.jsx', '.scss'],
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(env === 'development' ? 'development' : 'production'),
},
}),
new CleanWebpackPlugin(['dist', 'build']),
new webpack.NoErrorsPlugin(),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new HtmlWebpackPlugin({ template: './src/index.html' }),
preloadCSS,
mainCSS,
new StyleExtHtmlWebpackPlugin('bundle/preload.css'),
],
}
config.production = {
...config.default,
plugins: [
...config.default.plugins,
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
},
}),
]
}
config.development = {
...config.default,
devtool: 'source-map',
devServer: {
historyApiFallback: true,
inline: true,
stats: 'errors-only',
},
}
export default (env === 'development') ? config.development : config.production