Remove webpack dev server (#2821)

* Remove webpack-dev-server and move alias into base webpack config

* Fix typo
This commit is contained in:
Jakub Jóźwiak 2020-05-27 07:44:02 +02:00 committed by GitHub
parent 9fe05a5a7c
commit 00356a75d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 32 additions and 54 deletions

View File

@ -46,7 +46,7 @@
"build:release:www": "yarn polkadot-ci-ghact-build && yarn build:release:ipfs && yarn build:release:ghpages",
"build:www": "rm -rf packages/apps/build && mkdir -p packages/apps/build && yarn run build:i18n && cd packages/apps && NODE_ENV=production webpack --config webpack.config.js",
"build:electron": "yarn clean:electronBuild && yarn build:electronMain && yarn build:electronRenderer",
"build:devElectronRenderer": "cd packages/apps-electron && NODE_ENV=development webpack-dev-server --color --progress --config webpack.renderer.config.js",
"build:devElectronRenderer": "cd packages/apps-electron && NODE_ENV=development webpack --config webpack.renderer.config.js",
"build:electronRenderer": "cd packages/apps-electron && webpack --config webpack.renderer.config.js",
"build:devElectronMain": "cd packages/apps-electron && NODE_ENV=development webpack --config webpack.main.config.js",
"build:electronMain": "cd packages/apps-electron && webpack --config webpack.main.config.js",

View File

@ -21,7 +21,7 @@ function createWindow (): Promise<unknown> {
if (environment === 'development') {
win.webContents.openDevTools();
return win.loadURL('http://0.0.0.0:9000/');
return win.loadURL('http://0.0.0.0:3000/');
}
const mainFilePath = path.resolve(__dirname, 'index.html');

View File

@ -6,6 +6,7 @@
const TerserPlugin = require('terser-webpack-plugin');
const path = require('path');
const ENV = process.env.NODE_ENV || 'production';
const isProd = ENV === 'production';

View File

@ -4,38 +4,22 @@
/* eslint-disable camelcase */
const merge = require('webpack-merge');
const baseConfig = require('@polkadot/apps/webpack.base.config');
const path = require('path');
const merge = require('webpack-merge');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const findPackages = require('../../scripts/findPackages');
const baseConfig = require('@polkadot/apps/webpack.base.config');
const ENV = process.env.NODE_ENV || 'production';
const isProd = ENV === 'production';
const context = __dirname;
module.exports = merge(
baseConfig({
ENV,
alias: findPackages().reduce((alias, { dir, name }) => {
alias[name] = path.resolve(context, `../${dir}/src`);
return alias;
}, {}),
context,
isProd
}),
baseConfig(ENV, context),
{
devServer: {
compress: true,
contentBase: path.join(__dirname, 'build'),
hot: true,
liveReload: false,
port: 9000
},
devtool: isProd ? 'none' : 'source-map',
plugins: [
// It must be placed before HtmlWebpackPlugin
new CopyWebpackPlugin([{ from: '../apps/public' }]),
new HtmlWebpackPlugin({
PAGE_TITLE: 'Polkadot/Substrate Portal',

View File

@ -7,11 +7,12 @@
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { WebpackPluginServe } = require('webpack-plugin-serve');
const findPackages = require('../../scripts/findPackages');
function createWebpack ({ ENV, alias = {}, context, name = 'index' }) {
function createWebpack (ENV, context) {
const pkgJson = require(path.join(context, 'package.json'));
const isProd = ENV === 'production';
const hasPublic = fs.existsSync(path.join(context, 'public'));
@ -19,9 +20,25 @@ function createWebpack ({ ENV, alias = {}, context, name = 'index' }) {
? [new CopyWebpackPlugin([{ from: 'public' }])]
: [];
!isProd && plugins.push(
new WebpackPluginServe({
hmr: false, // switch off, Chrome WASM memory leak
liveReload: false, // explict off, overrides hmr
port: 3000,
progress: false, // since we have hmr off, disable
static: path.join(process.cwd(), '/build')
})
);
const alias = findPackages().reduce((alias, { dir, name }) => {
alias[name] = path.resolve(context, `../${dir}/src`);
return alias;
}, {});
return {
context,
entry: ['@babel/polyfill', `./src/${name}.tsx`],
entry: ['@babel/polyfill', './src/index.tsx'],
mode: ENV,
module: {
rules: [

View File

@ -8,47 +8,23 @@ const fs = require('fs');
const path = require('path');
const merge = require('webpack-merge');
const baseConfig = require('./webpack.base.config');
const { WebpackPluginServe } = require('webpack-plugin-serve');
const findPackages = require('../../scripts/findPackages');
const HtmlWebpackPlugin = require('html-webpack-plugin');
// const devtool = 'source-map'; // : 'cheap-eval-source-map',
const devtool = false;
const ENV = process.env.NODE_ENV || 'development';
const isProd = ENV === 'production';
const context = __dirname;
const hasPublic = fs.existsSync(path.join(context, 'public'));
const plugins = isProd
? []
: [
new WebpackPluginServe({
hmr: false, // switch off, Chrome WASM memory leak
liveReload: false, // explict off, overrides hmr
port: 3000,
progress: false, // since we have hmr off, disable
static: path.join(process.cwd(), '/build')
})
];
const ENV = process.env.NODE_ENV || 'development';
module.exports = merge(
baseConfig({
ENV,
alias: findPackages().reduce((alias, { dir, name }) => {
alias[name] = path.resolve(context, `../${dir}/src`);
return alias;
}, {}),
context
}),
baseConfig(ENV, context),
{
devtool,
plugins: plugins.concat([
devtool: false,
plugins: [
new HtmlWebpackPlugin({
PAGE_TITLE: 'Polkadot/Substrate Portal',
inject: true,
template: path.join(context, `${hasPublic ? 'public/' : ''}index.html`)
})
])
]
}
);