From 593b9028706b58070a2614fbcd04d28131a0d890 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Alvarez?= Date: Thu, 30 Nov 2023 17:13:04 +0100 Subject: [PATCH] feat(packages/sui-bundler): add server dev config --- .../sui-bundler/webpack.config.server.dev.js | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 packages/sui-bundler/webpack.config.server.dev.js diff --git a/packages/sui-bundler/webpack.config.server.dev.js b/packages/sui-bundler/webpack.config.server.dev.js new file mode 100644 index 000000000..94917cb60 --- /dev/null +++ b/packages/sui-bundler/webpack.config.server.dev.js @@ -0,0 +1,119 @@ +// @ts-check + +const path = require('path') +const webpack = require('webpack') +const HtmlWebpackPlugin = require('html-webpack-plugin') +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 {resolveLoader} = require('./shared/resolve-loader.js') +const createBabelRules = require('./shared/module-rules-babel.js') + +const outputPath = path.join(process.cwd(), '.sui/public') + +const {CI = false, PWD = '', CDN} = process.env + +process.env.NODE_ENV = 'development' + +/** @typedef {import('webpack').Configuration} WebpackConfig */ + +const webpackConfig = { + mode: 'development', + context: path.resolve(PWD, 'src'), + resolve: { + alias: { + ...defaultAlias, + ...aliasFromConfig + }, + fallback: { + fs: false, + http: require.resolve('stream-http'), + https: require.resolve('https-browserify'), + buffer: require.resolve('buffer/'), + url: require.resolve('url/'), + stream: false, + zlib: false, + timers: false + }, + modules: ['node_modules', path.resolve(process.cwd())], + extensions: ['.js', '.json'] + }, + stats: 'errors-only', + entry: { + app: [`webpack-hot-middleware/client?path=${CDN}__webpack_hmr`, MAIN_ENTRY_POINT] + }, + target: 'web', + optimization: { + checkWasmTypes: false, + emitOnErrors: false, + removeAvailableModules: false, + removeEmptyChunks: false, + runtimeChunk: true, + splitChunks: false + }, + output: { + path: outputPath, + pathinfo: false, + publicPath: CDN + }, + plugins: [ + new webpack.ProvidePlugin({ + process: 'process/browser.js' + }), + new webpack.EnvironmentPlugin(envVars(config.env)), + definePlugin({__DEV__: true}), + new MiniCssExtractPlugin(), + new HtmlWebpackPlugin({ + template: './index.html', + inject: true, + env: process.env + }), + new WebpackManifestPlugin({fileName: 'asset-manifest.json'}), + new webpack.HotModuleReplacementPlugin(), + new ReactRefreshWebpackPlugin({overlay: false}) + ], + resolveLoader, + module: { + rules: cleanList([ + createBabelRules({supportLegacyBrowsers, isDevelopment: true}), + { + test: /(\.css|\.scss)$/, + use: cleanList([ + MiniCssExtractPlugin.loader, + require.resolve('css-loader'), + when(config['externals-manifest'], () => ({ + loader: 'externals-manifest-loader', + options: { + manifestURL: config['externals-manifest'] + } + })), + { + loader: require.resolve('postcss-loader'), + options: { + postcssOptions: { + plugins: [ + require('autoprefixer')({ + overrideBrowserslist: config.targets + }) + ] + } + } + }, + require.resolve('@s-ui/sass-loader') + ]) + }, + when(config['externals-manifest'], () => manifestLoaderRules(config['externals-manifest'])) + ]) + }, + watch: !CI, + devtool: config.sourcemaps && config.sourcemaps.dev ? config.sourcemaps.dev : false +} + +module.exports = webpackConfig