2018-07-18 20:48:45 +02:00
|
|
|
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');
|
2018-12-05 02:03:42 +01:00
|
|
|
const COLORS = require('./src/constants/colors.js');
|
2018-07-18 20:48:45 +02:00
|
|
|
|
|
|
|
|
// Set up templating.
|
|
|
|
|
var nunjucks = Nunjucks.configure(path.resolve(__dirname, 'src'), {
|
2018-10-13 17:19:36 -07:00
|
|
|
noCache: true
|
2018-07-18 20:48:45 +02:00
|
|
|
});
|
2018-11-14 22:44:49 -08:00
|
|
|
nunjucks.addGlobal('DEBUG_AFRAME', !!process.env.DEBUG_AFRAME);
|
2018-07-20 15:42:47 +02:00
|
|
|
nunjucks.addGlobal('DEBUG_KEYBOARD', !!process.env.DEBUG_KEYBOARD);
|
2018-12-07 13:54:56 -08:00
|
|
|
nunjucks.addGlobal('DEBUG_INSPECTOR', !!process.env.DEBUG_INSPECTOR);
|
2018-07-18 20:48:45 +02:00
|
|
|
nunjucks.addGlobal('HOST', ip.address());
|
2018-07-20 15:42:47 +02:00
|
|
|
nunjucks.addGlobal('IS_PRODUCTION', process.env.NODE_ENV === 'production');
|
2018-12-05 02:03:42 +01:00
|
|
|
nunjucks.addGlobal('COLORS', COLORS);
|
2018-07-18 20:48:45 +02:00
|
|
|
|
|
|
|
|
// Initial Nunjucks render.
|
2018-12-09 04:15:53 -08:00
|
|
|
fs.writeFileSync('play.html', nunjucks.render('index.html'));
|
2018-07-18 20:48:45 +02:00
|
|
|
|
|
|
|
|
// 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 {
|
2018-12-09 04:15:53 -08:00
|
|
|
fs.writeFileSync('play.html', nunjucks.render('index.html'));
|
2018-07-18 20:48:45 +02:00
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PLUGINS = [new webpack.EnvironmentPlugin(['NODE_ENV'])];
|
|
|
|
|
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,
|
2018-10-13 17:19:36 -07:00
|
|
|
tdz: true
|
2018-07-18 20:48:45 +02:00
|
|
|
},
|
|
|
|
|
{
|
2018-10-13 17:19:36 -07:00
|
|
|
sourceMap: 'source-map'
|
2018-07-18 20:48:45 +02:00
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
devtool: '#inline-source-map',
|
|
|
|
|
devServer: {
|
2018-10-13 17:19:36 -07:00
|
|
|
disableHostCheck: true
|
2018-07-18 20:48:45 +02:00
|
|
|
},
|
|
|
|
|
entry: './src/index.js',
|
|
|
|
|
output: {
|
|
|
|
|
path: __dirname,
|
2018-10-13 17:19:36 -07:00
|
|
|
filename: 'build/build.js'
|
2018-07-18 20:48:45 +02:00
|
|
|
},
|
|
|
|
|
plugins: PLUGINS,
|
|
|
|
|
module: {
|
|
|
|
|
rules: [
|
|
|
|
|
{
|
|
|
|
|
test: /\.js/,
|
|
|
|
|
exclude: path =>
|
|
|
|
|
path.indexOf('node_modules') !== -1 || path.indexOf('panel') !== -1,
|
2018-10-13 17:19:36 -07:00
|
|
|
loader: 'babel-loader'
|
2018-07-18 20:48:45 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.glsl/,
|
|
|
|
|
exclude: /(node_modules)/,
|
2018-10-13 17:19:36 -07:00
|
|
|
loader: 'webpack-glsl-loader'
|
2018-07-18 20:48:45 +02:00
|
|
|
},
|
2018-10-10 22:12:17 -10:00
|
|
|
{
|
|
|
|
|
test: /\.css$/,
|
|
|
|
|
exclude: /(node_modules)/,
|
2018-10-13 17:19:36 -07:00
|
|
|
use: ['style-loader', 'css-loader']
|
2018-10-10 22:12:17 -10:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.(png|jpg)/,
|
2018-10-13 17:19:36 -07:00
|
|
|
loader: 'url-loader'
|
2018-10-10 22:12:17 -10:00
|
|
|
}
|
2018-10-13 17:19:36 -07:00
|
|
|
]
|
2018-07-18 20:48:45 +02:00
|
|
|
},
|
|
|
|
|
resolve: {
|
2018-10-13 17:19:36 -07:00
|
|
|
modules: [path.join(__dirname, 'node_modules')]
|
|
|
|
|
}
|
2018-07-18 20:48:45 +02:00
|
|
|
};
|