2020-03-27 20:59:38 +00:00
|
|
|
// Note: You must restart bin/webpack-dev-server for changes to take effect
|
|
|
|
|
|
|
|
const webpack = require('webpack');
|
2020-06-04 22:31:17 +00:00
|
|
|
const { join, resolve } = require('path');
|
2020-03-27 20:59:38 +00:00
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
|
|
const AssetsManifestPlugin = require('webpack-assets-manifest');
|
2020-05-18 02:02:57 +00:00
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
|
|
const HtmlWebpackHarddiskPlugin = require('html-webpack-harddisk-plugin');
|
2021-04-17 18:30:22 +00:00
|
|
|
const CopyPlugin = require('copy-webpack-plugin');
|
2021-03-23 20:22:10 +00:00
|
|
|
const { UnusedFilesWebpackPlugin } = require('unused-files-webpack-plugin');
|
2021-07-21 21:13:24 +00:00
|
|
|
const { env, settings, packsPath } = require('./configuration');
|
2020-03-27 20:59:38 +00:00
|
|
|
const rules = require('./rules');
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
entry: Object.assign(
|
2020-05-28 23:46:24 +00:00
|
|
|
{ application: resolve('app/application.js') },
|
2020-10-07 18:08:36 +00:00
|
|
|
{ styles: resolve(join(settings.source_path, 'styles/application.scss')) },
|
2020-03-27 20:59:38 +00:00
|
|
|
),
|
|
|
|
|
|
|
|
output: {
|
2021-07-21 21:13:24 +00:00
|
|
|
filename: packsPath('js/[name]-[chunkhash].js'),
|
|
|
|
chunkFilename: packsPath('js/[name]-[chunkhash].chunk.js'),
|
|
|
|
hotUpdateChunkFilename: packsPath('js/[id]-[hash].hot-update.js'),
|
|
|
|
path: join(__dirname, '..', 'static'),
|
|
|
|
publicPath: '/',
|
2020-03-27 20:59:38 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
optimization: {
|
|
|
|
runtimeChunk: {
|
|
|
|
name: 'common',
|
|
|
|
},
|
|
|
|
splitChunks: {
|
|
|
|
cacheGroups: {
|
|
|
|
default: false,
|
|
|
|
vendors: false,
|
|
|
|
common: {
|
|
|
|
name: 'common',
|
|
|
|
chunks: 'all',
|
|
|
|
minChunks: 2,
|
|
|
|
minSize: 0,
|
|
|
|
test: /^(?!.*[\\\/]node_modules[\\\/]react-intl[\\\/]).+$/,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
occurrenceOrder: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
module: {
|
|
|
|
rules: Object.keys(rules).map(key => rules[key]),
|
|
|
|
},
|
|
|
|
|
|
|
|
plugins: [
|
|
|
|
new webpack.EnvironmentPlugin(JSON.parse(JSON.stringify(env))),
|
|
|
|
new webpack.NormalModuleReplacementPlugin(
|
|
|
|
/^history\//, (resource) => {
|
|
|
|
// temporary fix for https://github.com/ReactTraining/react-router/issues/5576
|
|
|
|
// to reduce bundle size
|
|
|
|
resource.request = resource.request.replace(/^history/, 'history/es');
|
2020-10-07 18:08:36 +00:00
|
|
|
},
|
2020-03-27 20:59:38 +00:00
|
|
|
),
|
|
|
|
new MiniCssExtractPlugin({
|
2021-07-21 21:13:24 +00:00
|
|
|
filename: packsPath('css/[name]-[contenthash:8].css'),
|
|
|
|
chunkFilename: packsPath('css/[name]-[contenthash:8].chunk.css'),
|
2020-03-27 20:59:38 +00:00
|
|
|
}),
|
|
|
|
new AssetsManifestPlugin({
|
|
|
|
integrity: false,
|
|
|
|
entrypoints: true,
|
|
|
|
writeToDisk: true,
|
|
|
|
publicPath: true,
|
|
|
|
}),
|
2021-03-23 20:22:10 +00:00
|
|
|
// https://www.npmjs.com/package/unused-files-webpack-plugin#options
|
|
|
|
new UnusedFilesWebpackPlugin({
|
|
|
|
patterns: ['app/**/*.*'],
|
|
|
|
globOptions: {
|
|
|
|
ignore: ['node_modules/**/*', '**/__*__/**/*'],
|
|
|
|
},
|
|
|
|
}),
|
2020-05-18 02:02:57 +00:00
|
|
|
// https://github.com/ampedandwired/html-webpack-plugin
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: 'app/index.ejs',
|
|
|
|
chunksSortMode: 'manual',
|
2020-06-01 04:09:21 +00:00
|
|
|
chunks: ['common', 'locale_en', 'application', 'styles'],
|
2020-05-18 02:02:57 +00:00
|
|
|
alwaysWriteToDisk: true,
|
2020-07-15 16:10:27 +00:00
|
|
|
minify: {
|
|
|
|
collapseWhitespace: true,
|
|
|
|
removeComments: false,
|
|
|
|
removeRedundantAttributes: true,
|
|
|
|
removeScriptTypeAttributes: true,
|
|
|
|
removeStyleLinkTypeAttributes: true,
|
|
|
|
useShortDoctype: true,
|
|
|
|
},
|
2020-05-18 02:02:57 +00:00
|
|
|
}),
|
2021-07-21 21:13:24 +00:00
|
|
|
new HtmlWebpackHarddiskPlugin(),
|
2021-04-17 18:30:22 +00:00
|
|
|
new CopyPlugin({
|
|
|
|
patterns: [{
|
|
|
|
from: join(__dirname, '../node_modules/twemoji/assets/svg'),
|
|
|
|
to: join(__dirname, '../static/emoji'),
|
2021-04-17 19:21:12 +00:00
|
|
|
}, {
|
|
|
|
from: join(__dirname, '../node_modules/emoji-datasource/img/twitter/sheets/32.png'),
|
2021-07-10 05:43:49 +00:00
|
|
|
to: join(__dirname, '../static/emoji/sheet_13.png'),
|
2021-04-17 18:30:22 +00:00
|
|
|
}],
|
|
|
|
options: {
|
|
|
|
concurrency: 100,
|
|
|
|
},
|
|
|
|
}),
|
2020-03-27 20:59:38 +00:00
|
|
|
],
|
|
|
|
|
|
|
|
resolve: {
|
|
|
|
extensions: settings.extensions,
|
|
|
|
modules: [
|
|
|
|
resolve(settings.source_path),
|
|
|
|
'node_modules',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
|
|
|
|
resolveLoader: {
|
|
|
|
modules: ['node_modules'],
|
|
|
|
},
|
|
|
|
|
|
|
|
node: {
|
|
|
|
// Called by http-link-header in an API we never use, increases
|
|
|
|
// bundle size unnecessarily
|
|
|
|
Buffer: false,
|
|
|
|
},
|
|
|
|
};
|