-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
119 lines (116 loc) · 3.13 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
var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
module.exports = function(options) {
var entry, jsLoaders, plugins, cssLoaders;
switch (options.env) {
case 'dev':
console.log("# Development");
entry = [
"webpack-dev-server/client?http://localhost:3000",
"webpack/hot/only-dev-server",
path.resolve(__dirname, 'js/app.js')
];
cssLoaders = 'style-loader!css-loader!postcss-loader';
plugins = [
new webpack.HotModuleReplacementPlugin(),
new HtmlWebpackPlugin({
template: 'index.html',
inject: true
})
]
break;
case 'prod':
console.log("# Production");
entry = [
path.resolve(__dirname, 'js/app.js')
];
cssLoaders = ExtractTextPlugin.extract('style-loader', 'css-loader!postcss-loader');
plugins = [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}),
new HtmlWebpackPlugin({
template: 'index.html',
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true
},
inject: true
}),
new ExtractTextPlugin("css/main.css"),
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production")
}
})
];
break;
}
return {
entry: entry,
output: {
path: path.resolve(__dirname, 'build'),
filename: "js/bundle.js",
publicPath: ''
},
module: {
loaders: [
{
test: /\.json$/,
loader: 'json-loader'
},
{
test: /\.js$/,
loader: 'babel',
exclude: path.join(__dirname, '/node_modules/')
}, {
test: /\.css$/,
loader: cssLoaders
}, {
test: /\.jpe?g$|\.gif$|\.png$/i,
loader: "url-loader?limit=10000"
},
{
test: /\.(ttf|eot|svg|woff(2)?)(\?v=[\d.]+)?(\?[a-z0-9#-]+)?$/,
loader: 'url-loader?limit=100000&name=./css/[hash].[ext]'
}
]
},
plugins: plugins,
postcss: function() {
return [
require('postcss-import')({
glob: true,
onImport: function (files) {
files.forEach(this.addDependency);
}.bind(this)
}),
require('postcss-mixins')(),
require('postcss-simple-vars')(),
require('postcss-focus')(),
require('postcss-nested')(),
require('autoprefixer')({
browsers: ['last 2 versions', 'IE > 8']
}),
require('postcss-reporter')({
clearMessages: true
})
];
},
target: "web",
stats: false,
progress: true
}
}