gab-social/config/webpack/shared.js

107 lines
3.0 KiB
JavaScript
Raw Permalink Normal View History

2019-07-02 08:10:25 +01:00
// Note: You must restart bin/webpack-dev-server for changes to take effect
const webpack = require('webpack');
const { basename, dirname, join, relative, resolve } = require('path');
const { sync } = require('glob');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const AssetsManifestPlugin = require('webpack-assets-manifest');
const extname = require('path-complete-extname');
2020-03-04 04:59:11 +00:00
const { env, settings, output } = require('./configuration');
2019-07-02 08:10:25 +01:00
const rules = require('./rules');
2020-03-08 23:02:28 +00:00
const localePackPaths = require('./generateLocalePacks');
2019-07-02 08:10:25 +01:00
const extensionGlob = `**/*{${settings.extensions.join(',')}}*`;
const entryPath = join(settings.source_path, settings.source_entry_path);
const packPaths = sync(join(entryPath, extensionGlob));
module.exports = {
entry: Object.assign(
packPaths.reduce((map, entry) => {
const localMap = map;
const namespace = relative(join(entryPath), dirname(entry));
localMap[join(namespace, basename(entry, extname(entry)))] = resolve(entry);
return localMap;
}, {}),
localePackPaths.reduce((map, entry) => {
const localMap = map;
localMap[basename(entry, extname(entry, extname(entry)))] = resolve(entry);
return localMap;
}, {}),
),
output: {
filename: 'js/[name]-[chunkhash].js',
chunkFilename: 'js/[name]-[chunkhash].chunk.js',
hotUpdateChunkFilename: 'js/[id]-[hash].hot-update.js',
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.ProvidePlugin({
2020-04-08 02:06:59 +01:00
_s: `${resolve(settings.source_path)}/styles/global.css`,
}),
2019-07-02 08:10:25 +01:00
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',
2019-09-17 00:31:30 +01:00
ignoreOrder: true,
2019-07-02 08:10:25 +01:00
}),
new AssetsManifestPlugin({
integrity: false,
entrypoints: true,
writeToDisk: true,
publicPath: true,
}),
],
resolve: {
extensions: settings.extensions,
modules: [
resolve(settings.source_path),
'node_modules',
],
},
resolveLoader: {
modules: ['node_modules'],
},
node: {
2020-03-04 22:26:01 +00:00
// Called by http-link-header in an API we never use,
// increases bundle size unnecessarily
2019-07-02 08:10:25 +01:00
Buffer: false,
},
};