ThreeJS-Webpack-ES6-Boilerp.../webpack.config.js

85 lines
1.7 KiB
JavaScript
Raw Permalink Normal View History

2016-10-07 03:16:25 +00:00
// Global imports
2016-09-12 19:54:07 +00:00
var webpack = require('webpack'),
path = require('path');
2016-10-07 03:16:25 +00:00
// Paths
2016-09-12 19:54:07 +00:00
var entry = './src/js/app.js',
includePath = path.join(__dirname, 'src/js'),
nodeModulesPath = path.join(__dirname, 'node_modules'),
outputPath = path.join(__dirname, 'src/public/assets/js');
2016-10-07 03:16:25 +00:00
// Environment
2016-09-12 19:54:07 +00:00
var PROD = JSON.parse(process.env.NODE_ENV || 0);
2016-10-07 03:16:25 +00:00
// Dev environment
2016-09-12 19:54:07 +00:00
var env = 'dev',
time = Date.now(),
devtool = 'eval',
debug = true,
plugins = [
new webpack.NoErrorsPlugin(),
new webpack.DefinePlugin({
__ENV__: JSON.stringify(env),
___BUILD_TIME___: time
})
];
2016-10-07 03:16:25 +00:00
// Production environment
2016-09-12 19:54:07 +00:00
if(PROD) {
env = 'prod';
devtool = 'hidden-source-map';
debug = false;
outputPath = __dirname + '/build/public/assets/js';
uglifyOptions = {
sourceMap: false,
mangle: true,
compress: {
drop_console: true
},
output: {
comments: false
}
};
plugins.push(new webpack.optimize.UglifyJsPlugin(uglifyOptions));
}
console.log('Webpack build - ENV: ' + env + ' V: ' + time);
console.log(' - outputPath ', outputPath);
console.log(' - includePath ', includePath);
console.log(' - nodeModulesPath ', nodeModulesPath);
module.exports = {
stats: {
colors: true
},
debug: debug,
devtool: devtool,
devServer: {
contentBase: 'src/public'
},
entry: [
entry
],
output: {
path: outputPath,
publicPath: 'assets/js',
filename: 'app.js'
},
module: {
loaders: [
{
test: /\.js?$/,
loader: 'babel-loader',
query: {
presets: ['es2015']
},
include: [
includePath, nodeModulesPath
]
}
]
},
2016-10-07 03:16:25 +00:00
plugins: plugins
2016-09-12 19:54:07 +00:00
};