paricafe/webpack/plugins/index.ts

42 lines
1 KiB
TypeScript
Raw Normal View History

2018-03-02 16:32:18 -06:00
import * as fs from 'fs';
2018-02-22 13:53:33 -06:00
import * as webpack from 'webpack';
2018-03-02 16:32:18 -06:00
const WebpackOnBuildPlugin = require('on-build-webpack');
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
2018-02-24 23:32:37 -06:00
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
2018-02-25 00:50:25 -06:00
import chalk from 'chalk';
2018-02-22 13:53:33 -06:00
2017-11-22 15:51:32 -06:00
import consts from './consts';
2017-06-25 19:04:42 -05:00
import hoist from './hoist';
2017-11-28 03:14:24 -06:00
import minify from './minify';
2017-05-16 10:00:56 -05:00
const env = process.env.NODE_ENV;
const isProduction = env === 'production';
2017-11-03 03:46:42 -05:00
export default (version, lang) => {
2017-05-16 10:00:56 -05:00
const plugins = [
2018-03-02 16:32:18 -06:00
new HardSourceWebpackPlugin(),
2018-02-25 00:50:25 -06:00
new ProgressBarPlugin({
format: chalk` {cyan.bold yes we can} {bold [}:bar{bold ]} {green.bold :percent} {gray (:current/:total)} :elapseds`,
clear: false
}),
2018-02-22 13:53:33 -06:00
consts(lang),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
}
2018-03-02 16:32:18 -06:00
}),
new WebpackOnBuildPlugin(stats => {
fs.writeFileSync('./version.json', JSON.stringify({
version
}), 'utf-8');
2018-02-22 13:53:33 -06:00
})
2017-05-16 10:00:56 -05:00
];
2017-05-16 10:00:56 -05:00
if (isProduction) {
2018-02-14 21:36:42 -06:00
plugins.push(hoist());
2017-11-28 03:14:24 -06:00
plugins.push(minify());
2017-05-16 10:00:56 -05:00
}
2017-05-16 10:00:56 -05:00
return plugins;
};