2018-07-16 13:57:56 -04:00
|
|
|
const webpack = require('webpack');
|
2017-11-13 01:23:39 -05:00
|
|
|
const merge = require('webpack-merge');
|
|
|
|
const common = require('./webpack.web.common.js');
|
|
|
|
|
|
|
|
const CopyPlugin = require('copy-webpack-plugin');
|
|
|
|
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
|
|
|
|
const ManifestPlugin = require('webpack-manifest-plugin');
|
2018-03-15 16:59:10 -04:00
|
|
|
const CleanPlugin = require('clean-webpack-plugin');
|
2017-11-13 01:23:39 -05:00
|
|
|
|
|
|
|
const uglify = require('uglify-es');
|
|
|
|
|
2018-07-16 13:57:56 -04:00
|
|
|
// Get Git info
|
|
|
|
|
|
|
|
const commit_hash = require('child_process').execSync('git rev-parse HEAD').toString().trim();
|
|
|
|
|
2018-03-15 16:59:10 -04:00
|
|
|
/* global module Buffer */
|
|
|
|
|
2017-11-13 01:23:39 -05:00
|
|
|
const config = module.exports = merge(common, {
|
|
|
|
devtool: 'source-map',
|
|
|
|
|
|
|
|
plugins: [
|
2018-03-15 16:59:10 -04:00
|
|
|
new CleanPlugin(['dist']),
|
2017-11-13 01:23:39 -05:00
|
|
|
new UglifyJSPlugin({
|
|
|
|
sourceMap: true,
|
|
|
|
uglifyOptions: {
|
|
|
|
compress: {
|
2017-12-16 02:13:53 -05:00
|
|
|
keep_fnames: true,
|
|
|
|
keep_classnames: true
|
2017-11-13 01:23:39 -05:00
|
|
|
},
|
|
|
|
mangle: {
|
|
|
|
keep_classnames: true,
|
|
|
|
keep_fnames: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}),
|
2018-07-16 13:57:56 -04:00
|
|
|
new webpack.DefinePlugin({
|
|
|
|
__git_commit__: JSON.stringify(commit_hash)
|
|
|
|
}),
|
2017-11-13 01:23:39 -05:00
|
|
|
new CopyPlugin([
|
|
|
|
{
|
|
|
|
from: './src/entry.js',
|
|
|
|
to: 'script.min.js',
|
2018-03-15 16:59:10 -04:00
|
|
|
transform: content => {
|
2017-11-13 01:23:39 -05:00
|
|
|
const text = content.toString('utf8');
|
|
|
|
const minified = uglify.minify(text);
|
|
|
|
return (minified && minified.code) ? Buffer.from(minified.code) : content;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]),
|
|
|
|
new ManifestPlugin({
|
2018-03-15 16:59:10 -04:00
|
|
|
map: data => {
|
2017-11-13 01:23:39 -05:00
|
|
|
if ( data.name.endsWith('.scss') )
|
2018-03-15 16:59:10 -04:00
|
|
|
data.name = `${data.name.substr(0,data.name.length - 5)}.css`;
|
2017-11-13 01:23:39 -05:00
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
],
|
|
|
|
|
|
|
|
output: {
|
2018-03-30 23:34:56 -04:00
|
|
|
publicPath: '//cdn.frankerfacez.com/static/',
|
2017-11-13 01:23:39 -05:00
|
|
|
filename: '[name].[hash].js'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// This is why we can't have nice things.
|
|
|
|
// Why can't I just access process.env.NODE_ENV from
|
|
|
|
// one of these files when I set it with webpack's
|
|
|
|
// CLI? So stupid.
|
|
|
|
//
|
|
|
|
// So here we go.
|
|
|
|
// This is crap.
|
|
|
|
// But it works.
|
|
|
|
|
|
|
|
for(const rule of config.module.rules) {
|
2018-03-15 16:59:10 -04:00
|
|
|
if ( Array.isArray(rule.use) )
|
2017-11-13 01:23:39 -05:00
|
|
|
for(const use of rule.use)
|
|
|
|
if ( use.options && use.options.name && use.options.name.startsWith('[name].') )
|
2018-03-15 16:59:10 -04:00
|
|
|
use.options.name = `[name].[hash].${use.options.name.slice(7)}`;
|
2017-11-13 01:23:39 -05:00
|
|
|
}
|