Webpack optimizations (dev server) (#4279)
* Webpack optimizations (dev server) * Non-prod * Useless change
This commit is contained in:
parent
462ea6b085
commit
4990b2a3fe
12
package.json
12
package.json
@ -35,12 +35,12 @@
|
||||
"build:release:ghpages": "yarn polkadot-ci-ghact-docs",
|
||||
"build:release:www": "yarn polkadot-ci-ghact-build && yarn build:release:ipfs && yarn build:release:ghpages",
|
||||
"build:robohash": "node scripts/robohash.js",
|
||||
"build:www": "rm -rf packages/apps/build && mkdir -p packages/apps/build && yarn run build:i18n && cd packages/apps && yarn webpack --config webpack.config.js --mode production",
|
||||
"build:www": "rm -rf packages/apps/build && mkdir -p packages/apps/build && yarn run build:i18n && cd packages/apps && yarn webpack --config webpack.config.js",
|
||||
"build:electron": "yarn clean:electronBuild && yarn build:electronMain && yarn build:electronRenderer",
|
||||
"build:devElectronRenderer": "cd packages/apps-electron && yarn webpack --config webpack.renderer.js --mode development",
|
||||
"build:electronRenderer": "cd packages/apps-electron && yarn webpack --config webpack.renderer.js --mode production",
|
||||
"build:devElectronMain": "cd packages/apps-electron && yarn webpack --config webpack.main.js --mode development",
|
||||
"build:electronMain": "cd packages/apps-electron && yarn webpack --config webpack.main.js --mode production",
|
||||
"build:devElectronRenderer": "cd packages/apps-electron && yarn webpack --config webpack.renderer.js",
|
||||
"build:electronRenderer": "cd packages/apps-electron && yarn webpack --config webpack.renderer.js",
|
||||
"build:devElectronMain": "cd packages/apps-electron && yarn webpack --config webpack.main.js",
|
||||
"build:electronMain": "cd packages/apps-electron && yarn webpack --config webpack.main.js",
|
||||
"packElectron:test": "yarn build:release:electron && electron-builder --dir",
|
||||
"packElectron:mac": "yarn build:release:electron && electron-builder build --mac",
|
||||
"packElectron:win": "yarn build:release:electron && electron-builder build --win",
|
||||
@ -58,7 +58,7 @@
|
||||
"test": "polkadot-dev-run-test --selectProjects=fast-tests --silent --testPathIgnorePatterns slow --testNamePattern='^((?!--SLOW--).)*$'",
|
||||
"test:all": "polkadot-dev-run-test --selectProjects=all-tests --silent",
|
||||
"test:one": "polkadot-dev-run-test",
|
||||
"start": "yarn clean && cd packages/apps && yarn webpack --config webpack.serve.js --mode development --watch serve --port 3000",
|
||||
"start": "yarn clean && cd packages/apps && yarn webpack --watch serve --config webpack.serve.js --port 3000",
|
||||
"start:electron": "yarn clean:electronBuild && concurrently 'yarn build:devElectronMain && cd packages/apps-electron && electron ./build/electron.js' 'yarn build:devElectronRenderer'"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@ -13,6 +13,7 @@ function createWebpack () {
|
||||
electron: './src/electron',
|
||||
preload: './src/preload.ts'
|
||||
},
|
||||
mode: 'production',
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
|
||||
@ -13,7 +13,7 @@ const baseConfig = require('../apps/webpack.base.js');
|
||||
const context = __dirname;
|
||||
|
||||
module.exports = merge(
|
||||
baseConfig(context),
|
||||
baseConfig(context, 'development'),
|
||||
{
|
||||
plugins: [
|
||||
// It must be placed before HtmlWebpackPlugin
|
||||
|
||||
@ -23,7 +23,7 @@ function mapChunks (name, regs, inc) {
|
||||
}), {});
|
||||
}
|
||||
|
||||
function createWebpack (context) {
|
||||
function createWebpack (context, mode = 'production') {
|
||||
const pkgJson = require(path.join(context, 'package.json'));
|
||||
const alias = findPackages().reduce((alias, { dir, name }) => {
|
||||
alias[name] = path.resolve(context, `../${dir}/src`);
|
||||
@ -37,6 +37,7 @@ function createWebpack (context) {
|
||||
return {
|
||||
context,
|
||||
entry: ['@babel/polyfill', './src/index.tsx'],
|
||||
mode,
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
@ -56,6 +57,7 @@ function createWebpack (context) {
|
||||
exclude: /(node_modules)/,
|
||||
test: /\.(js|mjs|ts|tsx)$/,
|
||||
use: [
|
||||
require.resolve('thread-loader'),
|
||||
{
|
||||
loader: require.resolve('babel-loader'),
|
||||
options: require('@polkadot/dev/config/babel-config-webpack.cjs')
|
||||
@ -112,6 +114,7 @@ function createWebpack (context) {
|
||||
__filename: false
|
||||
},
|
||||
optimization: {
|
||||
minimize: mode === 'production',
|
||||
splitChunks: {
|
||||
cacheGroups: {
|
||||
...mapChunks('robohash', [
|
||||
@ -175,9 +178,6 @@ function createWebpack (context) {
|
||||
path: require.resolve('path-browserify'),
|
||||
stream: require.resolve('stream-browserify')
|
||||
}
|
||||
},
|
||||
watchOptions: {
|
||||
ignored: ['.yarn', 'build', 'node_modules']
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -2,21 +2,29 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const path = require('path');
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
const webpack = require('webpack');
|
||||
const { merge } = require('webpack-merge');
|
||||
|
||||
const baseConfig = require('./webpack.config.js');
|
||||
const baseConfig = require('./webpack.base.js');
|
||||
|
||||
module.exports = merge(
|
||||
baseConfig,
|
||||
baseConfig(__dirname, 'development'),
|
||||
{
|
||||
devServer: {
|
||||
open: true,
|
||||
open: false,
|
||||
static: path.resolve(__dirname, 'build')
|
||||
},
|
||||
mode: 'development',
|
||||
plugins: [
|
||||
new HtmlWebpackPlugin({
|
||||
PAGE_TITLE: 'Polkadot/Substrate Portal',
|
||||
inject: true,
|
||||
template: path.join(__dirname, 'public/index.html')
|
||||
}),
|
||||
new webpack.HotModuleReplacementPlugin()
|
||||
]
|
||||
],
|
||||
watchOptions: {
|
||||
ignored: ['.yarn', 'build', 'node_modules']
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user