-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
webpack.config.js
126 lines (121 loc) · 3.35 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
var MinifyPlugin = require('babel-minify-webpack-plugin');
var Nunjucks = require('nunjucks');
var fs = require('fs');
var htmlMinify = require('html-minifier').minify;
var ip = require('ip');
var path = require('path');
var webpack = require('webpack');
const COLORS = require('./src/constants/colors.js');
const HtmlWebpackPlugin = require('html-webpack-plugin');
// Set up templating.
var nunjucks = Nunjucks.configure(path.resolve(__dirname, 'src'), {
noCache: true
});
nunjucks.addGlobal('DEBUG_AFRAME', !!process.env.DEBUG_AFRAME);
// nunjucks.addGlobal('DEBUG_KEYBOARD', !!process.env.DEBUG_KEYBOARD);
nunjucks.addGlobal('DEBUG_KEYBOARD', true);
nunjucks.addGlobal('DEBUG_INSPECTOR', !!process.env.DEBUG_INSPECTOR);
nunjucks.addGlobal('HOST', ip.address());
nunjucks.addGlobal('IS_PRODUCTION', process.env.NODE_ENV === 'production');
nunjucks.addGlobal('COLORS', COLORS);
// Initial Nunjucks render.
fs.writeFileSync('index.html', nunjucks.render('index.html'));
// For development, watch HTML for changes to compile Nunjucks.
// The production Express server will handle Nunjucks by itself.
if (process.env.NODE_ENV !== 'production') {
fs.watch('src', { recursive: true }, (eventType, filename) => {
if (filename.indexOf('.html') === -1) {
return;
}
try {
fs.writeFileSync('index.html', nunjucks.render('index.html'));
} catch (e) {
console.error(e);
}
});
}
PLUGINS = [new webpack.EnvironmentPlugin(['NODE_ENV']), new HtmlWebpackPlugin({template: path.resolve('./index.html')})];
if (process.env.NODE_ENV === 'production') {
PLUGINS.push(
new MinifyPlugin(
{
booleans: true,
builtIns: true,
consecutiveAdds: true,
deadcode: true,
evaluate: false,
flipComparisons: true,
guards: true,
infinity: true,
mangle: false,
memberExpressions: true,
mergeVars: true,
numericLiterals: true,
propertyLiterals: true,
regexpConstructors: true,
removeUndefined: true,
replace: true,
simplify: true,
simplifyComparisons: true,
typeConstructors: true,
undefinedToVoid: true,
keepFnName: true,
keepClassName: true,
tdz: true
}
)
);
}
module.exports = {
devServer: {
disableHostCheck: true,
contentBase: "./build",
},
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'build'),
filename: 'bundle.js'
},
plugins: PLUGINS,
module: {
rules: [
{
test: /\.js/,
exclude: path =>
path.indexOf('node_modules') !== -1 || path.indexOf('panel') !== -1,
loader: 'babel-loader'
},
{
test: /\.glsl/,
exclude: /(node_modules)/,
loader: 'webpack-glsl-loader'
},
{
test: /\.(png|jpg)/,
loader: 'url-loader'
},
{
test: /\.styl$/,
exclude: /(node_modules)/,
loaders: [
'style-loader',
{
loader: 'css-loader',
options: {url: false}
},
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: (loader) => [require('autoprefixer')()]
}
},
'stylus-loader'
]
}
]
},
resolve: {
modules: [path.join(__dirname, 'node_modules')]
}
};