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
|
2018-02-26 00:31:45 +00:00
|
|
|
var env = 'dev',
|
|
|
|
time = Date.now(),
|
2016-09-12 19:54:07 +00:00
|
|
|
devtool = 'eval',
|
2018-02-26 00:31:45 +00:00
|
|
|
mode = 'development',
|
|
|
|
stats = 'minimal',
|
2016-09-12 19:54:07 +00:00
|
|
|
plugins = [
|
2018-02-26 00:31:45 +00:00
|
|
|
//new webpack.NoErrorsPlugin(),
|
2016-09-12 19:54:07 +00:00
|
|
|
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';
|
2018-02-26 00:31:45 +00:00
|
|
|
mode = 'production';
|
|
|
|
stats = 'none';
|
2016-09-12 19:54:07 +00:00
|
|
|
outputPath = __dirname + '/build/public/assets/js';
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('Webpack build - ENV: ' + env + ' V: ' + time);
|
|
|
|
console.log(' - outputPath ', outputPath);
|
|
|
|
console.log(' - includePath ', includePath);
|
|
|
|
console.log(' - nodeModulesPath ', nodeModulesPath);
|
|
|
|
|
|
|
|
module.exports = {
|
2018-02-26 00:31:45 +00:00
|
|
|
// Here the application starts executing
|
|
|
|
// and webpack starts bundling
|
2016-09-12 19:54:07 +00:00
|
|
|
entry: [
|
|
|
|
entry
|
|
|
|
],
|
2018-02-26 00:31:45 +00:00
|
|
|
|
|
|
|
// options related to how webpack emits results
|
2016-09-12 19:54:07 +00:00
|
|
|
output: {
|
2018-02-26 00:31:45 +00:00
|
|
|
// the target directory for all output files
|
|
|
|
// must be an absolute path (use the Node.js path module)
|
2016-09-12 19:54:07 +00:00
|
|
|
path: outputPath,
|
2018-02-26 00:31:45 +00:00
|
|
|
// the url to the output directory resolved relative to the HTML page
|
2016-09-12 19:54:07 +00:00
|
|
|
publicPath: 'assets/js',
|
2018-02-26 00:31:45 +00:00
|
|
|
// the filename template for entry chunks
|
2016-09-12 19:54:07 +00:00
|
|
|
filename: 'app.js'
|
|
|
|
},
|
2018-02-26 00:31:45 +00:00
|
|
|
|
|
|
|
mode: mode,
|
|
|
|
|
|
|
|
// configuration regarding modules
|
2016-09-12 19:54:07 +00:00
|
|
|
module: {
|
2018-02-26 00:31:45 +00:00
|
|
|
// rules for modules (configure loaders, parser options, etc.)
|
|
|
|
rules: [
|
2016-09-12 19:54:07 +00:00
|
|
|
{
|
2018-02-26 00:31:45 +00:00
|
|
|
// these are matching conditions, each accepting a regular expression or string
|
|
|
|
// test and include have the same behavior, both must be matched
|
|
|
|
// exclude must not be matched (takes preference over test and include)
|
|
|
|
// Best practices:
|
|
|
|
// - Use RegExp only in test and for filename matching
|
|
|
|
// - Use arrays of absolute paths in include and exclude
|
|
|
|
// - Try to avoid exclude and prefer include
|
2016-09-12 19:54:07 +00:00
|
|
|
test: /\.js?$/,
|
2018-02-26 00:31:45 +00:00
|
|
|
// the loader which should be applied, it'll be resolved relative to the context
|
|
|
|
// -loader suffix is no longer optional in webpack2 for clarity reasons
|
|
|
|
// see webpack 1 upgrade guide
|
|
|
|
use: {
|
|
|
|
loader: 'babel-loader',
|
2016-09-12 19:54:07 +00:00
|
|
|
},
|
2018-02-26 00:31:45 +00:00
|
|
|
include: includePath,
|
|
|
|
exclude: nodeModulesPath,
|
2016-09-12 19:54:07 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2018-02-26 00:31:45 +00:00
|
|
|
|
|
|
|
// options for resolving module requests
|
|
|
|
// (does not apply to resolving to loaders)
|
|
|
|
resolve: {
|
|
|
|
|
|
|
|
// directories where to look for modules,
|
|
|
|
modules: [
|
|
|
|
'node_modules',
|
|
|
|
path.resolve(__dirname, 'app')
|
|
|
|
],
|
|
|
|
|
|
|
|
// extensions that are used
|
|
|
|
extensions: ['.js', '.json', '.css'],
|
|
|
|
},
|
|
|
|
|
|
|
|
performance: {
|
|
|
|
hints: 'warning' // enum
|
|
|
|
},
|
|
|
|
|
|
|
|
// lets you precisely control what bundle information gets displayed
|
|
|
|
stats: stats,
|
|
|
|
|
|
|
|
// enhance debugging by adding meta info for the browser devtools
|
|
|
|
// source-map most detailed at the expense of build speed.
|
|
|
|
devtool: devtool, // enum
|
|
|
|
|
|
|
|
devServer: {
|
|
|
|
contentBase: 'src/public'
|
|
|
|
},
|
|
|
|
|
2016-10-07 03:16:25 +00:00
|
|
|
plugins: plugins
|
2016-09-12 19:54:07 +00:00
|
|
|
};
|