Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(packages/sui-bundler): add server dev config #1673

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions packages/sui-bundler/webpack.config.server.dev.js
Original file line number Diff line number Diff line change
@@ -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
Loading