-
Notifications
You must be signed in to change notification settings - Fork 286
/
webpack.config.js
executable file
·167 lines (152 loc) · 5.2 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
var path = require('path');
var chalk = require('chalk');
var webpack = require('webpack');
var ExtractTextWebpackPlugin = require("extract-text-webpack-plugin");
//https://github.com/webpack-contrib/extract-text-webpack-plugin/blob/webpack-1/README.md
//[name] the name of the chunk
//[contenthash] a hash of the content of the extracted file
var extractPlugin = new ExtractTextWebpackPlugin("[name].[contenthash].css");
var WebpackMd5Hash = require('webpack-md5-hash');
var webpackMd5HashPlugin = new WebpackMd5Hash();
var HtmlWebpackPlugin = require('html-webpack-plugin');
//https://github.com/jantimon/html-webpack-plugin/issues/133
var indexHtmlWebpackPlugin = new HtmlWebpackPlugin({
filename: './index.html',
template: '!!html-loader!./src/core/template.html',
hash: false,
inject: 'body',
// chunks: ["runtime", "globe", "index"]
chunks: ["index"]
});
var webappHtmlWebpackPlugin = new HtmlWebpackPlugin({
filename: './webapp.html',
template: '!!ejs-loader!./src/webapp/template.html',
hash: false,
inject: 'body',
// chunks: ["runtime", "webapp", "globe"]
chunks: ["webapp"]
});
// var commonsChunkPlugin = new webpack.optimize.CommonsChunkPlugin({
// // name: "globe",
// // chunks: ["globe"]
// names: ["globe", "runtime"]
// });
var buildFolder = "buildOutput";
var PRODUCTION = process.env.NODE_ENV === 'production';
var es6Promise = "./node_modules/es6-promise/dist/es6-promise.auto.min.js";
module.exports = {
entry: {
// globe: "./src/core/world/Globe.ts",
index: [es6Promise, "./src/core/index.ts"],
webapp: [es6Promise, "./src/webapp/index.jsx"]
},
output: {
path: path.resolve(__dirname, buildFolder),
filename: "[name].[chunkhash].js",
// publicPath: buildFolder + "/",
devtoolModuleFilenameTemplate: 'webpack:///[absolute-resource-path]'
},
// devtool: PRODUCTION ? 'hidden-source-map' : 'cheap-module-eval-source-map'
devtool: PRODUCTION ? false : 'source-map',
resolve: {
extensions: [".webpack.js", ".web.js", ".ts", ".tsx", ".js", ".jsx", ".scss", ".png"],
alias: {
core: path.resolve(__dirname, "./src/core"),
world: path.resolve(__dirname, "./src/core/world"),
webapp: path.resolve(__dirname, "./src/webapp")
}
},
module: {
rules: [{
test: /\.tsx?$/,
use: {
loader: "ts-loader"
}
},
{
test: /\.jsx?$/,
use: {
loader: "babel-loader"
}
},
{
test: /\.scss$/,
use: extractPlugin.extract({
use: [{
loader: "css-loader",
options: {
modules: true,
localIdentName: "[name]__[local]___[hash:base64:5]"
}
}, {
loader: "sass-loader"
}]
})
},
{
test: /\.(png|jpeg|jpg|gif)$/,
use: {
loader: "file-loader"
}
},
{
test: /\.(otf|ttf|eot|woff|woff2).*/,
use: {
loader: "file-loader"
}
},
{
test: /\.html$/,
use: {
loader: "html-loader",
options: {
attrs: ['img:src']
}
}
}
]
},
plugins: [
// commonsChunkPlugin,
extractPlugin,
webpackMd5HashPlugin,
indexHtmlWebpackPlugin,
webappHtmlWebpackPlugin
]
};
if (PRODUCTION) {
module.exports.plugins.push(
//add DefinePlugin for production to save 88KB for React build
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: false
})
);
} else {
//https://github.com/webpack/webpack/issues/708
module.exports.plugins.push(
function() {
this.plugin("done", function(stats) {
var errors = stats.compilation.errors;
if (errors && errors.length > 0) {
console.log("");
console.log(chalk.red("----------------------------------------------------------------"));
errors.forEach(function(err) {
var msg = '';
// var msg = chalk.red(`ERROR in ${err.module.userRequest},`);
// msg += chalk.blue(`(${err.location.line},${err.location.character}),`);
msg += chalk.red(err.message);
console.log(msg);
// console.log(err);
});
console.log(chalk.red("----------------------------------------------------------------"));
process.exit(1);
}
});
}
);
}