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-07-21 21:43:41 +00:00
|
|
|
const { env, settings, output } = require('./configuration');
|
2020-03-27 20:59:38 +00:00
|
|
|
const rules = require('./rules');
|
|
|
|
|
2021-09-05 18:21:39 +00:00
|
|
|
const { FE_SUBDIRECTORY } = require(join(__dirname, '..', 'app', 'soapbox', 'build_config'));
|
2021-09-03 18:49:18 +00:00
|
|
|
|
2021-09-05 21:42:48 +00:00
|
|
|
const makeHtmlConfig = (params = {}) => {
|
|
|
|
return Object.assign({
|
|
|
|
template: 'app/index.ejs',
|
|
|
|
chunksSortMode: 'manual',
|
|
|
|
chunks: ['common', 'locale_en', 'application', 'styles'],
|
|
|
|
alwaysWriteToDisk: true,
|
|
|
|
minify: {
|
|
|
|
collapseWhitespace: true,
|
|
|
|
removeComments: false,
|
|
|
|
removeRedundantAttributes: true,
|
|
|
|
removeScriptTypeAttributes: true,
|
|
|
|
removeStyleLinkTypeAttributes: true,
|
|
|
|
useShortDoctype: true,
|
|
|
|
},
|
|
|
|
}, params);
|
2021-08-31 00:17:32 +00:00
|
|
|
};
|
|
|
|
|
2020-03-27 20:59:38 +00:00
|
|
|
module.exports = {
|
2021-09-11 00:30:47 +00:00
|
|
|
entry: {
|
|
|
|
application: resolve('app/application.js'),
|
|
|
|
},
|
2020-03-27 20:59:38 +00:00
|
|
|
|
|
|
|
output: {
|
2021-07-21 21:43:41 +00:00
|
|
|
filename: 'packs/js/[name]-[chunkhash].js',
|
|
|
|
chunkFilename: 'packs/js/[name]-[chunkhash].chunk.js',
|
2021-09-05 21:42:48 +00:00
|
|
|
hotUpdateChunkFilename: 'packs/js/[id]-[contenthash].hot-update.js',
|
2021-07-21 21:43:41 +00:00
|
|
|
path: output.path,
|
2021-09-05 18:21:39 +00:00
|
|
|
publicPath: join(FE_SUBDIRECTORY, '/'),
|
2020-03-27 20:59:38 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
optimization: {
|
2021-09-05 21:42:48 +00:00
|
|
|
chunkIds: 'total-size',
|
|
|
|
moduleIds: 'size',
|
2020-03-27 20:59:38 +00:00
|
|
|
runtimeChunk: {
|
|
|
|
name: 'common',
|
|
|
|
},
|
|
|
|
splitChunks: {
|
|
|
|
cacheGroups: {
|
|
|
|
default: false,
|
2021-09-05 21:42:48 +00:00
|
|
|
defaultVendors: false,
|
2020-03-27 20:59:38 +00:00
|
|
|
common: {
|
|
|
|
name: 'common',
|
|
|
|
chunks: 'all',
|
|
|
|
minChunks: 2,
|
|
|
|
minSize: 0,
|
|
|
|
test: /^(?!.*[\\\/]node_modules[\\\/]react-intl[\\\/]).+$/,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
module: {
|
2021-09-09 17:00:42 +00:00
|
|
|
rules,
|
2020-03-27 20:59:38 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
plugins: [
|
|
|
|
new webpack.EnvironmentPlugin(JSON.parse(JSON.stringify(env))),
|
2021-09-05 21:42:48 +00:00
|
|
|
new webpack.ProvidePlugin({
|
|
|
|
process: 'process/browser',
|
|
|
|
}),
|
2020-03-27 20:59:38 +00:00
|
|
|
new MiniCssExtractPlugin({
|
2021-07-21 21:43:41 +00:00
|
|
|
filename: 'packs/css/[name]-[contenthash:8].css',
|
|
|
|
chunkFilename: 'packs/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-08-31 00:17:32 +00:00
|
|
|
// https://github.com/jantimon/html-webpack-plugin#options
|
2021-09-05 21:42:48 +00:00
|
|
|
new HtmlWebpackPlugin(makeHtmlConfig()),
|
|
|
|
new HtmlWebpackPlugin(makeHtmlConfig({ filename: '404.html' })),
|
2021-07-21 21:13:24 +00:00
|
|
|
new HtmlWebpackHarddiskPlugin(),
|
2021-04-17 18:30:22 +00:00
|
|
|
new CopyPlugin({
|
|
|
|
patterns: [{
|
2021-09-12 15:51:58 +00:00
|
|
|
from: join(__dirname, '../node_modules/twemoji/assets/svg'),
|
|
|
|
to: join(output.path, 'packs/emoji'),
|
|
|
|
}, {
|
2021-09-03 18:06:04 +00:00
|
|
|
from: join(__dirname, '../app/instance'),
|
|
|
|
to: join(output.path, 'instance'),
|
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',
|
|
|
|
],
|
2021-09-20 20:33:28 +00:00
|
|
|
alias: {
|
|
|
|
// Override tabler's package.json to allow importing .svg files directly
|
|
|
|
// https://stackoverflow.com/a/35990101/8811886
|
|
|
|
'@tabler': resolve('node_modules', '@tabler'),
|
2021-09-20 22:05:59 +00:00
|
|
|
'icons': resolve('app', 'icons'),
|
2021-09-20 20:33:28 +00:00
|
|
|
},
|
2021-09-05 21:42:48 +00:00
|
|
|
fallback: {
|
|
|
|
path: require.resolve('path-browserify'),
|
|
|
|
util: require.resolve('util'),
|
|
|
|
},
|
2020-03-27 20:59:38 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
resolveLoader: {
|
|
|
|
modules: ['node_modules'],
|
|
|
|
},
|
|
|
|
};
|