-
Notifications
You must be signed in to change notification settings - Fork 4
/
webpack.config.build.js
107 lines (103 loc) · 2.77 KB
/
webpack.config.build.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
'use strict';
var autoprefixer = require('autoprefixer');
var ChildCompilerLoaderListPlugin = require(
'child-compiler-loader-list-webpack-plugin'
);
var DefinePlugin = require('webpack').DefinePlugin;
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var HtmlWepbackPlugin = require('html-webpack-plugin');
var OfflinePlugin = require('offline-plugin');
var UglifyJsPlugin = require('webpack').optimize.UglifyJsPlugin;
// This is used to extract the css into a separate stylesheet. We do that only
// for production builds so development builds can make use of hot module
// replacement and faster builds (extracting takes time).
//
// Multiple extractions could be done, as one option a critical section of css
// could be extracted and with a small plugin to HtmlWebpackPlugin, inlined
// into the output html.
var mainCssExtraction = new ExtractTextPlugin('[contenthash].css');
var loaders = [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
// Autoload style files named like an included jsx file.
{
test: /\.jsx$/,
exclude: /node_modules/,
loader: 'baggage-loader?[file].styl',
},
{
test: /\.styl$/,
loader: mainCssExtraction.extract(
'style-loader',
'css-loader!postcss-loader!stylus-loader'
),
},
{
test: /\.(png|webm|svg)$/,
loader: 'file-loader',
},
{
test: /\.json$/,
loader: 'json-loader',
},
{
test: /[/\\]soundjs/,
loader: 'exports-loader?createjs!script-loader',
},
];
module.exports = {
context: __dirname,
entry: {
main: './src',
},
output: {
path: 'dist',
filename: '[hash].js',
},
module: {
loaders: loaders,
},
resolve: {
modulesDirectories: ['node_modules', 'vendor'],
extensions: ['', '.min.js', '.js', '.jsx'],
},
resolveLoaders: {
modulesDirectories: ['node_modules', 'web_loaders'],
},
postcss: function() {
return [autoprefixer];
},
plugins: [
mainCssExtraction,
new DefinePlugin({
'process.env.NODE_ENV': '"production"',
}),
new OfflinePlugin({
caches: {
main: ['index.html', '*'],
},
updateStrategy: 'changed',
// scope is any subdirectory the deployed files will be under.
// scope: '/rwd-game-boiler/',
}),
new ChildCompilerLoaderListPlugin({
test: /html-webpack-plugin/,
loaders: loaders
.filter(function(loader) {return loader.test.source !== '\\.styl$';})
.concat({
test: /\.styl$/,
loader: 'css-loader/locals!stylus-loader',
}),
}),
new HtmlWepbackPlugin({
filename: 'index.html',
template: './src/index.bake.html',
inject: 'body',
chunks: ['main'],
}),
new UglifyJsPlugin(),
],
};