1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-06-27 21:05:53 +00:00
FrankerFaceZ/webpack.web.prod.js

68 lines
1.5 KiB
JavaScript
Raw Normal View History

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 TerserPlugin = require('terser-webpack-plugin');
const { WebpackManifestPlugin } = require('webpack-manifest-plugin');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
2017-11-13 01:23:39 -05:00
const Terser = require('terser');
2017-11-13 01:23:39 -05:00
// Get Git info
const commit_hash = require('child_process').execSync('git rev-parse HEAD').toString().trim();
/* global module Buffer */
const minifier = content => {
const text = content.toString('utf8');
const minified = Terser.minify(text);
return (minified && minified.code) ? Buffer.from(minified.code) : content;
};
module.exports = merge(common, {
mode: 'production',
2017-11-13 01:23:39 -05:00
devtool: 'source-map',
optimization: {
concatenateModules: false,
minimizer: [
new TerserPlugin({
sourceMap: true,
terserOptions: {
2017-11-13 01:23:39 -05:00
keep_classnames: true,
keep_fnames: true
}
})
]
},
plugins: [
new CleanWebpackPlugin(),
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',
transform: minifier
2017-11-13 01:23:39 -05:00
}
]),
new WebpackManifestPlugin({
publicPath: '',
map: data => {
2017-11-13 01:23:39 -05:00
if ( data.name.endsWith('.scss') )
data.name = `${data.name.substr(0,data.name.length - 5)}.css`;
2017-11-13 01:23:39 -05:00
return data;
}
})
],
output: {
publicPath: '//cdn.frankerfacez.com/static/',
2017-11-13 01:23:39 -05:00
filename: '[name].[hash].js'
}
});