soapbox/webpack/shared.js

106 wiersze
3.0 KiB
JavaScript
Czysty Zwykły widok Historia

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');
const { basename, 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');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackHarddiskPlugin = require('html-webpack-harddisk-plugin');
2020-03-27 20:59:38 +00:00
const extname = require('path-complete-extname');
2020-06-01 04:09:21 +00:00
const { env, settings, output } = require('./configuration');
2020-03-27 20:59:38 +00:00
const rules = require('./rules');
const localePackPaths = require('./generateLocalePacks');
module.exports = {
entry: Object.assign(
{ application: resolve('app/application.js') },
2020-03-27 20:59:38 +00:00
localePackPaths.reduce((map, entry) => {
const localMap = map;
localMap[basename(entry, extname(entry, extname(entry)))] = resolve(entry);
return localMap;
}, {}),
2020-06-01 04:09:21 +00:00
{ styles: resolve(join(settings.source_path, 'styles/application.scss')) }
2020-03-27 20:59:38 +00:00
),
output: {
filename: 'js/[name]-[chunkhash].js',
chunkFilename: 'js/[name]-[chunkhash].chunk.js',
hotUpdateChunkFilename: 'js/[id]-[hash].hot-update.js',
2020-03-27 20:59:38 +00:00
path: output.path,
publicPath: output.publicPath,
},
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');
}
),
new MiniCssExtractPlugin({
filename: 'css/[name]-[contenthash:8].css',
chunkFilename: 'css/[name]-[contenthash:8].chunk.css',
2020-03-27 20:59:38 +00:00
}),
new AssetsManifestPlugin({
integrity: false,
entrypoints: true,
writeToDisk: true,
publicPath: true,
}),
// 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'],
alwaysWriteToDisk: true,
}),
new HtmlWebpackHarddiskPlugin({
outputPath: join(__dirname, '..', 'static'),
}),
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,
},
};