-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.production.config.js
63 lines (62 loc) · 1.56 KB
/
webpack.production.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
var config = require('./config');
var path = require('path');
var webpack = require('webpack');
var fs = require('fs');
module.exports = {
devtool: 'cheap-module-source-map',
entry: './src/main.js',
output: {
path: './dist',
filename: 'build-[hash].js'
},
plugins: [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new webpack.DefinePlugin(config.globals),
function () {
this.plugin("done", function (statsData) {
var stats = statsData.toJson();
if (!stats.errors.length) {
var htmlFileName = "index.html";
var html = fs.readFileSync(path.join(__dirname, htmlFileName), "utf8");
var htmlOutput = html.replace(
/<script src="build\.js/i,
"<script src=\"./" + stats.assetsByChunkName.main[0]);
fs.writeFileSync(path.join(__dirname, "dist", htmlFileName), htmlOutput);
}
});
}
],
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel',
include: path.join(__dirname, 'src')
},
{
test: /\.scss$/,
loaders: ["style", "css", "sass"]
},
{
test: /\.css$/,
loader: 'style-loader'
},
{
test: /\.css$/,
loader: "css-loader",
query: {
modules: true,
importLoaders: true,
localIdentName: '[name]__[local]'
}
},
{
test: /\.json$/,
loader: "json-loader"
}
]
}
};