2019-04-05 02:23:40 +07:00
|
|
|
const webpack = require('webpack');
|
|
|
|
const HTMLWebpackPlugin = require('html-webpack-plugin');
|
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
|
|
const UglifyJsWebpackPlugin = require('uglifyjs-webpack-plugin');
|
|
|
|
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
|
|
|
const _ = require('lodash');
|
|
|
|
const merge = require('webpack-merge');
|
2019-10-08 03:19:18 +07:00
|
|
|
|
|
|
|
const env = require('../config/env');
|
|
|
|
|
|
|
|
const baseConfig = require('./webpack.config');
|
2019-04-05 02:23:40 +07:00
|
|
|
const getPackageJson = require('./getPackageJson');
|
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
const { version, name, license } = getPackageJson('version', 'name', 'license');
|
2019-04-05 02:23:40 +07:00
|
|
|
|
|
|
|
const banner = `
|
|
|
|
Name: [name]
|
|
|
|
Generated on: ${Date.now()}
|
|
|
|
Package: ${name}
|
|
|
|
Version: v${version}
|
|
|
|
License: ${license}
|
|
|
|
`;
|
2019-02-03 17:23:33 +07:00
|
|
|
|
|
|
|
const prodConf = {
|
2019-04-05 02:23:40 +07:00
|
|
|
mode: 'production',
|
2019-02-03 17:23:33 +07:00
|
|
|
|
|
|
|
entry: {
|
2019-06-20 19:37:28 +07:00
|
|
|
main: ['babel-polyfill', 'whatwg-fetch', `${env.SRC_ROOT}/index.tsx`],
|
2019-02-03 17:23:33 +07:00
|
|
|
},
|
|
|
|
|
|
|
|
module: {
|
2019-04-05 02:23:40 +07:00
|
|
|
rules: [],
|
2019-02-03 17:23:33 +07:00
|
|
|
},
|
|
|
|
|
|
|
|
plugins: [
|
2019-04-05 02:23:40 +07:00
|
|
|
new webpack.DefinePlugin({
|
|
|
|
__DEBUG__: false,
|
|
|
|
'process.env.NODE_ENV': '"production"',
|
|
|
|
__APP_VERSION__: `"${version}"`,
|
|
|
|
}),
|
2019-02-03 17:23:33 +07:00
|
|
|
new MiniCssExtractPlugin({
|
2019-04-05 02:23:40 +07:00
|
|
|
filename: 'style.[contenthash].css',
|
2019-02-03 17:23:33 +07:00
|
|
|
}),
|
|
|
|
new HTMLWebpackPlugin({
|
2019-04-05 02:23:40 +07:00
|
|
|
title: 'ToReplaceByTitle',
|
2019-05-04 17:13:29 +07:00
|
|
|
__UI_OPTIONS: 'ToReplaceByVerdaccioUI',
|
2019-04-05 02:23:40 +07:00
|
|
|
scope: 'ToReplaceByScope',
|
2019-05-04 17:13:29 +07:00
|
|
|
basename: 'ToReplaceByPrefix',
|
2019-04-05 02:23:40 +07:00
|
|
|
logo: 'ToReplaceByLogo',
|
2019-04-26 02:42:48 +07:00
|
|
|
primary_color: 'ToReplaceByPrimaryColor',
|
2019-04-05 02:23:40 +07:00
|
|
|
filename: 'index.html',
|
2019-06-20 19:37:28 +07:00
|
|
|
favicon: `${env.SRC_ROOT}/template/favicon.ico`,
|
2019-04-05 02:23:40 +07:00
|
|
|
verdaccioURL: 'ToReplaceByVerdaccio',
|
2019-04-14 04:27:44 +07:00
|
|
|
version_app: 'ToReplaceByVersion',
|
2019-06-20 19:37:28 +07:00
|
|
|
template: `${env.SRC_ROOT}/template/index.html`,
|
2019-02-03 17:23:33 +07:00
|
|
|
debug: false,
|
2019-04-05 02:23:40 +07:00
|
|
|
inject: true,
|
|
|
|
}),
|
|
|
|
new webpack.BannerPlugin(banner),
|
2019-02-03 17:23:33 +07:00
|
|
|
],
|
|
|
|
|
|
|
|
optimization: {
|
|
|
|
minimizer: [
|
|
|
|
new UglifyJsWebpackPlugin({
|
2019-04-05 02:23:40 +07:00
|
|
|
sourceMap: true,
|
2019-02-03 17:23:33 +07:00
|
|
|
}),
|
2019-04-05 02:23:40 +07:00
|
|
|
new OptimizeCSSAssetsPlugin({}),
|
|
|
|
],
|
|
|
|
},
|
2019-02-03 17:23:33 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
prodConf.module.rules = baseConfig.module.rules
|
2019-06-20 19:37:28 +07:00
|
|
|
.filter(loader => Array.isArray(loader.use) && loader.use.find(v => /css/.test(v.loader.split('-')[0])))
|
|
|
|
.forEach(loader => {
|
2019-02-03 17:23:33 +07:00
|
|
|
loader.use = [MiniCssExtractPlugin.loader].concat(_.tail(loader.use));
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = merge(baseConfig, prodConf);
|