Merge pull request #16969 from vector-im/gsouquet-nightly-react-prod

This commit is contained in:
Germain 2021-04-19 09:19:57 +01:00 committed by GitHub
commit 4d6a8f9194
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,8 +5,8 @@ const TerserPlugin = require('terser-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin'); const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const webpack = require("webpack"); const webpack = require("webpack");
let og_image_url = process.env.RIOT_OG_IMAGE_URL; let ogImageUrl = process.env.RIOT_OG_IMAGE_URL;
if (!og_image_url) og_image_url = 'https://app.element.io/themes/element/img/logos/opengraph.png'; if (!ogImageUrl) ogImageUrl = 'https://app.element.io/themes/element/img/logos/opengraph.png';
const additionalPlugins = [ const additionalPlugins = [
// This is where you can put your customisation replacements. // This is where you can put your customisation replacements.
@ -18,6 +18,20 @@ module.exports = (env, argv) => {
// We override this via environment variable to avoid duplicating the scripts // We override this via environment variable to avoid duplicating the scripts
// in `package.json` just for a different mode. // in `package.json` just for a different mode.
argv.mode = "development"; argv.mode = "development";
// More and more people are using nightly build as their main client
// Libraries like React have a development build that is useful
// when working on the app but adds significant runtime overhead
// We want to use the React production build but not compile the whole
// application to productions standards
additionalPlugins.concat([
new webpack.EnvironmentPlugin({
"NODE_ENV": "production",
}),
new webpack.DefinePlugin({
"process.env.NODE_ENV": "production",
}),
]);
} }
const development = {}; const development = {};
@ -152,8 +166,8 @@ module.exports = (env, argv) => {
}, },
loader: 'babel-loader', loader: 'babel-loader',
options: { options: {
cacheDirectory: true cacheDirectory: true,
} },
}, },
{ {
test: /\.css$/, test: /\.css$/,
@ -164,7 +178,7 @@ module.exports = (env, argv) => {
options: { options: {
importLoaders: 1, importLoaders: 1,
sourceMap: true, sourceMap: true,
} },
}, },
{ {
loader: 'postcss-loader', loader: 'postcss-loader',
@ -202,7 +216,7 @@ module.exports = (env, argv) => {
"local-plugins": true, "local-plugins": true,
}, },
}, },
] ],
}, },
{ {
test: /\.scss$/, test: /\.scss$/,
@ -213,7 +227,7 @@ module.exports = (env, argv) => {
options: { options: {
importLoaders: 1, importLoaders: 1,
sourceMap: true, sourceMap: true,
} },
}, },
{ {
loader: 'postcss-loader', loader: 'postcss-loader',
@ -241,7 +255,7 @@ module.exports = (env, argv) => {
"local-plugins": true, "local-plugins": true,
}, },
}, },
] ],
}, },
{ {
test: /\.wasm$/, test: /\.wasm$/,
@ -311,7 +325,7 @@ module.exports = (env, argv) => {
}, },
], ],
}, },
] ],
}, },
plugins: [ plugins: [
@ -332,7 +346,7 @@ module.exports = (env, argv) => {
excludeChunks: ['mobileguide', 'usercontent', 'jitsi'], excludeChunks: ['mobileguide', 'usercontent', 'jitsi'],
minify: argv.mode === 'production', minify: argv.mode === 'production',
vars: { vars: {
og_image_url: og_image_url, og_image_url: ogImageUrl,
}, },
}), }),
@ -438,6 +452,7 @@ function getAssetOutputPath(url, resourcePath) {
* be placed directly into things like CSS files. * be placed directly into things like CSS files.
* *
* @param {string} path Some path to a file. * @param {string} path Some path to a file.
* @returns {string} converted path
*/ */
function toPublicPath(path) { function toPublicPath(path) {
return path.replace(/\\/g, '/'); return path.replace(/\\/g, '/');