From ffc6bebb8d383f5492bc8ca21d35f94e26a252cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Alvarez?= Date: Thu, 4 Jan 2024 11:30:56 +0100 Subject: [PATCH 1/5] feat(packages/sui-bundler): add webpack cache --- ...er.dev.js => webpack.config.client.dev.js} | 20 ++++++++++++------- packages/sui-bundler/webpack.config.dev.js | 6 ++++++ packages/sui-bundler/webpack.config.prod.js | 6 ++++++ packages/sui-bundler/webpack.config.server.js | 10 +++++++++- 4 files changed, 34 insertions(+), 8 deletions(-) rename packages/sui-bundler/{webpack.config.server.dev.js => webpack.config.client.dev.js} (82%) diff --git a/packages/sui-bundler/webpack.config.server.dev.js b/packages/sui-bundler/webpack.config.client.dev.js similarity index 82% rename from packages/sui-bundler/webpack.config.server.dev.js rename to packages/sui-bundler/webpack.config.client.dev.js index 94917cb60..3e8170c18 100644 --- a/packages/sui-bundler/webpack.config.server.dev.js +++ b/packages/sui-bundler/webpack.config.client.dev.js @@ -7,14 +7,14 @@ const {WebpackManifestPlugin} = require('webpack-manifest-plugin') const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin') const MiniCssExtractPlugin = require('mini-css-extract-plugin') -const {envVars, MAIN_ENTRY_POINT, config, cleanList, when} = require('./shared/index.js') -const definePlugin = require('./shared/define.js') -const manifestLoaderRules = require('./shared/module-rules-manifest-loader.js') -const {aliasFromConfig, defaultAlias} = require('./shared/resolve-alias.js') -const {supportLegacyBrowsers} = require('./shared/config.js') +const {envVars, MAIN_ENTRY_POINT, config, cleanList, when} = require('@s-ui/bundler/shared/index.js') +const definePlugin = require('@s-ui/bundler/shared/define.js') +const manifestLoaderRules = require('@s-ui/bundler/shared/module-rules-manifest-loader.js') +const {aliasFromConfig, defaultAlias} = require('@s-ui/bundler/shared/resolve-alias.js') +const {supportLegacyBrowsers} = require('@s-ui/bundler/shared/config.js') -const {resolveLoader} = require('./shared/resolve-loader.js') -const createBabelRules = require('./shared/module-rules-babel.js') +const {resolveLoader} = require('@s-ui/bundler/shared/resolve-loader.js') +const createBabelRules = require('@s-ui/bundler/shared/module-rules-babel.js') const outputPath = path.join(process.cwd(), '.sui/public') @@ -25,6 +25,7 @@ process.env.NODE_ENV = 'development' /** @typedef {import('webpack').Configuration} WebpackConfig */ const webpackConfig = { + name: 'client', mode: 'development', context: path.resolve(PWD, 'src'), resolve: { @@ -49,6 +50,11 @@ const webpackConfig = { entry: { app: [`webpack-hot-middleware/client?path=${CDN}__webpack_hmr`, MAIN_ENTRY_POINT] }, + cache: { + type: 'filesystem', + cacheDirectory: path.resolve(process.cwd(), '.sui/cache'), + compression: 'gzip' + }, target: 'web', optimization: { checkWasmTypes: false, diff --git a/packages/sui-bundler/webpack.config.dev.js b/packages/sui-bundler/webpack.config.dev.js index e207479c9..d4d2e410e 100644 --- a/packages/sui-bundler/webpack.config.dev.js +++ b/packages/sui-bundler/webpack.config.dev.js @@ -23,6 +23,7 @@ process.env.NODE_ENV = 'development' /** @typedef {import('webpack').Configuration} WebpackConfig */ const webpackConfig = { + name: 'client-local', mode: 'development', context: path.resolve(PWD, 'src'), resolve: { @@ -51,6 +52,11 @@ const webpackConfig = { static: outputPath, hot: true }, + cache: { + type: 'filesystem', + cacheDirectory: path.resolve(process.cwd(), '.sui/cache'), + compression: 'gzip' + }, target: 'web', optimization: { checkWasmTypes: false, diff --git a/packages/sui-bundler/webpack.config.prod.js b/packages/sui-bundler/webpack.config.prod.js index 1f22b70df..35cf8c7e5 100644 --- a/packages/sui-bundler/webpack.config.prod.js +++ b/packages/sui-bundler/webpack.config.prod.js @@ -35,6 +35,7 @@ const target = supportLegacyBrowsers ? ['web', 'es5'] : 'web' /** @type {WebpackConfig} */ const webpackConfig = { devtool: sourceMap, + name: 'client', mode: 'production', target, context: path.resolve(CWD, 'src'), @@ -66,6 +67,11 @@ const webpackConfig = { minimizer: [minifyJs({extractComments, sourceMap}), minifyCss()].filter(Boolean), runtimeChunk: true }, + cache: { + type: 'filesystem', + cacheDirectory: path.resolve(process.cwd(), '.sui/cache'), + compression: false + }, plugins: cleanList([ new webpack.ProvidePlugin({ process: 'process/browser' diff --git a/packages/sui-bundler/webpack.config.server.js b/packages/sui-bundler/webpack.config.server.js index b4b02df35..5764796bf 100644 --- a/packages/sui-bundler/webpack.config.server.js +++ b/packages/sui-bundler/webpack.config.server.js @@ -12,10 +12,13 @@ const filename = '[name].[chunkhash:8].js' /** @typedef {import('webpack').Configuration} WebpackConfig */ +const isProduction = process.env.NODE_ENV === 'production' + /** @type {WebpackConfig} */ const webpackConfig = { + name: 'server', context: path.resolve(process.cwd(), 'src'), - mode: process.env.NODE_ENV === 'production' ? 'production' : 'development', + mode: isProduction ? 'production' : 'development', resolve: { alias: {...aliasFromConfig}, extensions: ['.js', '.json'], @@ -34,6 +37,11 @@ const webpackConfig = { minimize: true, nodeEnv: false }, + cache: { + type: 'filesystem', + cacheDirectory: path.resolve(process.cwd(), '.sui/cache'), + compression: !isProduction ? 'gzip' : false + }, externals: [webpackNodeExternals()], plugins: [new webpack.DefinePlugin({'global.GENTLY': false})], resolveLoader, From 6b5e59fadfa0d21d9b4ecc900e1501d3f0e3bd46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Alvarez?= Date: Thu, 4 Jan 2024 11:31:26 +0100 Subject: [PATCH 2/5] feat(packages/sui-ssr): update sui bundler client config and add inspect for nodemon --- packages/sui-ssr/bin/sui-ssr-dev.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/sui-ssr/bin/sui-ssr-dev.js b/packages/sui-ssr/bin/sui-ssr-dev.js index daee97fdd..e745f875c 100644 --- a/packages/sui-ssr/bin/sui-ssr-dev.js +++ b/packages/sui-ssr/bin/sui-ssr-dev.js @@ -14,7 +14,7 @@ const webpack = require('webpack') const webpackDevMiddleware = require('webpack-dev-middleware') const webpackHotMiddleware = require('webpack-hot-middleware') const nodemon = require('nodemon') -const clientConfig = require('@s-ui/bundler/webpack.config.server.dev.js') +const clientConfig = require('@s-ui/bundler/webpack.config.client.dev.js') const linkLoaderConfigBuilder = require('@s-ui/bundler/loaders/linkLoaderConfigBuilder.js') const serverConfigFactory = require('../compiler/server.js') @@ -76,7 +76,7 @@ const start = ({packagesToLink, linkAll}) => { const app = express() const clientCompiler = webpack( linkLoaderConfigBuilder({ - config: require('@s-ui/bundler/webpack.config.server.dev.js'), + config: clientConfig, linkAll, packagesToLink }) @@ -135,6 +135,7 @@ const start = ({packagesToLink, linkAll}) => { const script = nodemon({ script: `${SERVER_OUTPUT_PATH}/index.js`, watch: [SERVER_OUTPUT_PATH], + nodeArgs: '--inspect', delay: 200 }) From 5a6cae09241167a2b4b861056f687d8ff8fb81cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Alvarez?= Date: Thu, 4 Jan 2024 11:34:36 +0100 Subject: [PATCH 3/5] feat(packages/sui-bundler): update imports --- packages/sui-bundler/webpack.config.client.dev.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/sui-bundler/webpack.config.client.dev.js b/packages/sui-bundler/webpack.config.client.dev.js index 3e8170c18..5dcfb4387 100644 --- a/packages/sui-bundler/webpack.config.client.dev.js +++ b/packages/sui-bundler/webpack.config.client.dev.js @@ -7,14 +7,14 @@ const {WebpackManifestPlugin} = require('webpack-manifest-plugin') const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin') const MiniCssExtractPlugin = require('mini-css-extract-plugin') -const {envVars, MAIN_ENTRY_POINT, config, cleanList, when} = require('@s-ui/bundler/shared/index.js') -const definePlugin = require('@s-ui/bundler/shared/define.js') -const manifestLoaderRules = require('@s-ui/bundler/shared/module-rules-manifest-loader.js') -const {aliasFromConfig, defaultAlias} = require('@s-ui/bundler/shared/resolve-alias.js') -const {supportLegacyBrowsers} = require('@s-ui/bundler/shared/config.js') +const {envVars, MAIN_ENTRY_POINT, config, cleanList, when} = require('./shared/index.js') +const definePlugin = require('./shared/define.js') +const manifestLoaderRules = require('./shared/module-rules-manifest-loader.js') +const {aliasFromConfig, defaultAlias} = require('./shared/resolve-alias.js') +const {supportLegacyBrowsers} = require('./shared/config.js') -const {resolveLoader} = require('@s-ui/bundler/shared/resolve-loader.js') -const createBabelRules = require('@s-ui/bundler/shared/module-rules-babel.js') +const {resolveLoader} = require('./shared/resolve-loader.js') +const createBabelRules = require('./shared/module-rules-babel.js') const outputPath = path.join(process.cwd(), '.sui/public') From fd24c7116a25fd7d39239b964b29b774ace989f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Alvarez?= Date: Thu, 4 Jan 2024 11:47:45 +0100 Subject: [PATCH 4/5] feat(packages/sui-bundler): add cacheDir in config --- packages/sui-bundler/shared/config.js | 2 ++ packages/sui-bundler/webpack.config.client.dev.js | 4 ++-- packages/sui-bundler/webpack.config.dev.js | 4 ++-- packages/sui-bundler/webpack.config.prod.js | 4 ++-- packages/sui-bundler/webpack.config.server.js | 3 ++- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/sui-bundler/shared/config.js b/packages/sui-bundler/shared/config.js index 807567c5e..57c1f65c3 100644 --- a/packages/sui-bundler/shared/config.js +++ b/packages/sui-bundler/shared/config.js @@ -1,4 +1,5 @@ /* Extract sui-bundler from package.json -> "config": {"sui-bundler": { ... }} */ +const path = require('path') const {config: packageJsonConfig = {}} = require(`${process.cwd()}/package.json`) const {'sui-bundler': config = {}} = packageJsonConfig @@ -8,3 +9,4 @@ exports.config = config exports.supportLegacyBrowsers = supportLegacyBrowsers exports.extractComments = extractComments exports.sourceMap = (sourcemaps && sourcemaps.prod) || false +exports.cacheDirectory = path.resolve(process.cwd(), '.sui/cache') diff --git a/packages/sui-bundler/webpack.config.client.dev.js b/packages/sui-bundler/webpack.config.client.dev.js index 5dcfb4387..cd23dbe80 100644 --- a/packages/sui-bundler/webpack.config.client.dev.js +++ b/packages/sui-bundler/webpack.config.client.dev.js @@ -11,7 +11,7 @@ const {envVars, MAIN_ENTRY_POINT, config, cleanList, when} = require('./shared/i const definePlugin = require('./shared/define.js') const manifestLoaderRules = require('./shared/module-rules-manifest-loader.js') const {aliasFromConfig, defaultAlias} = require('./shared/resolve-alias.js') -const {supportLegacyBrowsers} = require('./shared/config.js') +const {supportLegacyBrowsers, cacheDirectory} = require('./shared/config.js') const {resolveLoader} = require('./shared/resolve-loader.js') const createBabelRules = require('./shared/module-rules-babel.js') @@ -52,7 +52,7 @@ const webpackConfig = { }, cache: { type: 'filesystem', - cacheDirectory: path.resolve(process.cwd(), '.sui/cache'), + cacheDirectory, compression: 'gzip' }, target: 'web', diff --git a/packages/sui-bundler/webpack.config.dev.js b/packages/sui-bundler/webpack.config.dev.js index d4d2e410e..94b1547ac 100644 --- a/packages/sui-bundler/webpack.config.dev.js +++ b/packages/sui-bundler/webpack.config.dev.js @@ -9,7 +9,7 @@ const {envVars, MAIN_ENTRY_POINT, config, cleanList, when} = require('./shared/i const definePlugin = require('./shared/define.js') const manifestLoaderRules = require('./shared/module-rules-manifest-loader.js') const {aliasFromConfig, defaultAlias} = require('./shared/resolve-alias.js') -const {supportLegacyBrowsers} = require('./shared/config.js') +const {supportLegacyBrowsers, cacheDirectory} = require('./shared/config.js') const {resolveLoader} = require('./shared/resolve-loader.js') const createBabelRules = require('./shared/module-rules-babel.js') @@ -54,7 +54,7 @@ const webpackConfig = { }, cache: { type: 'filesystem', - cacheDirectory: path.resolve(process.cwd(), '.sui/cache'), + cacheDirectory, compression: 'gzip' }, target: 'web', diff --git a/packages/sui-bundler/webpack.config.prod.js b/packages/sui-bundler/webpack.config.prod.js index 35cf8c7e5..7e81eebca 100644 --- a/packages/sui-bundler/webpack.config.prod.js +++ b/packages/sui-bundler/webpack.config.prod.js @@ -11,7 +11,7 @@ const InlineChunkHtmlPlugin = require('./shared/inline-chunk-html-plugin.js') const {when, cleanList, envVars, MAIN_ENTRY_POINT, config} = require('./shared/index.js') const {aliasFromConfig} = require('./shared/resolve-alias.js') -const {extractComments, sourceMap, supportLegacyBrowsers} = require('./shared/config.js') +const {extractComments, sourceMap, supportLegacyBrowsers, cacheDirectory} = require('./shared/config.js') const {resolveLoader} = require('./shared/resolve-loader.js') const createBabelRules = require('./shared/module-rules-babel.js') const sassRules = require('./shared/module-rules-sass.js') @@ -69,7 +69,7 @@ const webpackConfig = { }, cache: { type: 'filesystem', - cacheDirectory: path.resolve(process.cwd(), '.sui/cache'), + cacheDirectory, compression: false }, plugins: cleanList([ diff --git a/packages/sui-bundler/webpack.config.server.js b/packages/sui-bundler/webpack.config.server.js index 5764796bf..515b4515b 100644 --- a/packages/sui-bundler/webpack.config.server.js +++ b/packages/sui-bundler/webpack.config.server.js @@ -3,6 +3,7 @@ const webpackNodeExternals = require('webpack-node-externals') const path = require('path') const {config, when, cleanList} = require('./shared/index.js') +const {cacheDirectory} = require('./shared/config.js') const createBabelRules = require('./shared/module-rules-babel.js') const manifestLoaderRules = require('./shared/module-rules-manifest-loader.js') const {aliasFromConfig} = require('./shared/resolve-alias.js') @@ -39,7 +40,7 @@ const webpackConfig = { }, cache: { type: 'filesystem', - cacheDirectory: path.resolve(process.cwd(), '.sui/cache'), + cacheDirectory, compression: !isProduction ? 'gzip' : false }, externals: [webpackNodeExternals()], From fc596c267d4c361463336065a9c4e4562c8f0468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Alvarez?= Date: Thu, 4 Jan 2024 12:51:32 +0100 Subject: [PATCH 5/5] feat(packages/sui-bundler): use brotli compression --- packages/sui-bundler/webpack.config.client.dev.js | 2 +- packages/sui-bundler/webpack.config.dev.js | 2 +- packages/sui-bundler/webpack.config.server.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/sui-bundler/webpack.config.client.dev.js b/packages/sui-bundler/webpack.config.client.dev.js index cd23dbe80..fda8faf99 100644 --- a/packages/sui-bundler/webpack.config.client.dev.js +++ b/packages/sui-bundler/webpack.config.client.dev.js @@ -53,7 +53,7 @@ const webpackConfig = { cache: { type: 'filesystem', cacheDirectory, - compression: 'gzip' + compression: 'brotli' }, target: 'web', optimization: { diff --git a/packages/sui-bundler/webpack.config.dev.js b/packages/sui-bundler/webpack.config.dev.js index 94b1547ac..a0f68c89e 100644 --- a/packages/sui-bundler/webpack.config.dev.js +++ b/packages/sui-bundler/webpack.config.dev.js @@ -55,7 +55,7 @@ const webpackConfig = { cache: { type: 'filesystem', cacheDirectory, - compression: 'gzip' + compression: 'brotli' }, target: 'web', optimization: { diff --git a/packages/sui-bundler/webpack.config.server.js b/packages/sui-bundler/webpack.config.server.js index 515b4515b..b54d80415 100644 --- a/packages/sui-bundler/webpack.config.server.js +++ b/packages/sui-bundler/webpack.config.server.js @@ -41,7 +41,7 @@ const webpackConfig = { cache: { type: 'filesystem', cacheDirectory, - compression: !isProduction ? 'gzip' : false + compression: !isProduction ? 'brotli' : false }, externals: [webpackNodeExternals()], plugins: [new webpack.DefinePlugin({'global.GENTLY': false})],