mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-11 23:26:30 +08:00
chore: bump rspack (#14957)
#### PR Dependency Tree * **PR #14957** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Updated minimum Node version requirement to 22.12.0 or later. * Updated build tool dependencies including rspack and related packages. * Removed CI-specific logging behavior from development server. * Migrated to native HTML plugin integration for improved build efficiency. * Simplified build configuration by removing unused experimental options. <!-- review_stack_entry_start --> [](https://app.coderabbit.ai/change-stack/toeverything/AFFiNE/pull/14957) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -27,9 +27,6 @@ export function assertRspackSupportedPackageName(name: string) {
|
||||
);
|
||||
}
|
||||
|
||||
const IN_CI = !!process.env.CI;
|
||||
const httpProxyMiddlewareLogLevel = IN_CI ? 'silent' : 'error';
|
||||
|
||||
export const DEFAULT_DEV_SERVER_CONFIG: RspackDevServerConfiguration = {
|
||||
host: '0.0.0.0',
|
||||
allowedHosts: 'all',
|
||||
@@ -61,18 +58,15 @@ export const DEFAULT_DEV_SERVER_CONFIG: RspackDevServerConfiguration = {
|
||||
{
|
||||
context: '/api',
|
||||
target: 'http://localhost:3010',
|
||||
logLevel: httpProxyMiddlewareLogLevel,
|
||||
},
|
||||
{
|
||||
context: '/socket.io',
|
||||
target: 'http://localhost:3010',
|
||||
ws: true,
|
||||
logLevel: httpProxyMiddlewareLogLevel,
|
||||
},
|
||||
{
|
||||
context: '/graphql',
|
||||
target: 'http://localhost:3010',
|
||||
logLevel: httpProxyMiddlewareLogLevel,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@@ -3,9 +3,11 @@ import { readFileSync } from 'node:fs';
|
||||
|
||||
import { Path, ProjectRoot } from '@affine-tools/utils/path';
|
||||
import { Repository } from '@napi-rs/simple-git';
|
||||
import HTMLPlugin from 'html-webpack-plugin';
|
||||
import { HtmlRspackPlugin, type HtmlRspackPluginOptions } from '@rspack/core';
|
||||
import { once } from 'lodash-es';
|
||||
|
||||
type HtmlRspackPluginInstance = InstanceType<typeof HtmlRspackPlugin>;
|
||||
|
||||
type PluginLike = {
|
||||
apply: (compiler: CompilerLike) => void;
|
||||
};
|
||||
@@ -109,45 +111,44 @@ function getHTMLPluginOptions(BUILD_CONFIG: BUILD_CONFIG_TYPE) {
|
||||
templateParameters: templateParams,
|
||||
chunks: ['app'],
|
||||
scriptLoading: 'blocking',
|
||||
} satisfies HTMLPlugin.Options;
|
||||
} satisfies HtmlRspackPluginOptions;
|
||||
}
|
||||
|
||||
const AssetsManifestPlugin = {
|
||||
apply(compiler: CompilerLike) {
|
||||
compiler.hooks.compilation.tap('assets-manifest-plugin', compilation => {
|
||||
HTMLPlugin.getHooks(compilation).beforeAssetTagGeneration.tap(
|
||||
'assets-manifest-plugin',
|
||||
arg => {
|
||||
if (!compilation.getAsset('assets-manifest.json')) {
|
||||
compilation.emitAsset(
|
||||
`assets-manifest.json`,
|
||||
createRawSource(
|
||||
compiler,
|
||||
JSON.stringify(
|
||||
{
|
||||
...arg.assets,
|
||||
js: arg.assets.js.map(file =>
|
||||
file.substring(arg.assets.publicPath.length)
|
||||
),
|
||||
css: arg.assets.css.map(file =>
|
||||
file.substring(arg.assets.publicPath.length)
|
||||
),
|
||||
gitHash: gitShortHash(),
|
||||
description: DESCRIPTION,
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
),
|
||||
{
|
||||
immutable: false,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return arg;
|
||||
HtmlRspackPlugin.getCompilationHooks(
|
||||
compilation
|
||||
).beforeAssetTagGeneration.tap('assets-manifest-plugin', arg => {
|
||||
if (!compilation.getAsset('assets-manifest.json')) {
|
||||
compilation.emitAsset(
|
||||
`assets-manifest.json`,
|
||||
createRawSource(
|
||||
compiler,
|
||||
JSON.stringify(
|
||||
{
|
||||
...arg.assets,
|
||||
js: arg.assets.js.map(file =>
|
||||
file.substring(arg.assets.publicPath.length)
|
||||
),
|
||||
css: arg.assets.css.map(file =>
|
||||
file.substring(arg.assets.publicPath.length)
|
||||
),
|
||||
gitHash: gitShortHash(),
|
||||
description: DESCRIPTION,
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
),
|
||||
{
|
||||
immutable: false,
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
return arg;
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
@@ -162,22 +163,21 @@ const GlobalErrorHandlerPlugin = {
|
||||
compiler.hooks.compilation.tap(
|
||||
'global-error-handler-plugin',
|
||||
compilation => {
|
||||
HTMLPlugin.getHooks(compilation).beforeAssetTagGeneration.tap(
|
||||
'global-error-handler-plugin',
|
||||
arg => {
|
||||
if (!compilation.getAsset(globalErrorHandler[0])) {
|
||||
compilation.emitAsset(
|
||||
globalErrorHandler[0],
|
||||
createRawSource(compiler, globalErrorHandler[1])
|
||||
);
|
||||
arg.assets.js.unshift(
|
||||
arg.assets.publicPath + globalErrorHandler[0]
|
||||
);
|
||||
}
|
||||
|
||||
return arg;
|
||||
HtmlRspackPlugin.getCompilationHooks(
|
||||
compilation
|
||||
).beforeAssetTagGeneration.tap('global-error-handler-plugin', arg => {
|
||||
if (!compilation.getAsset(globalErrorHandler[0])) {
|
||||
compilation.emitAsset(
|
||||
globalErrorHandler[0],
|
||||
createRawSource(compiler, globalErrorHandler[1])
|
||||
);
|
||||
arg.assets.js.unshift(
|
||||
arg.assets.publicPath + globalErrorHandler[0]
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
return arg;
|
||||
});
|
||||
}
|
||||
);
|
||||
},
|
||||
@@ -186,7 +186,7 @@ const GlobalErrorHandlerPlugin = {
|
||||
const CorsPlugin = {
|
||||
apply(compiler: CompilerLike) {
|
||||
compiler.hooks.compilation.tap('html-js-cors-plugin', compilation => {
|
||||
HTMLPlugin.getHooks(compilation).alterAssetTags.tap(
|
||||
HtmlRspackPlugin.getCompilationHooks(compilation).alterAssetTags.tap(
|
||||
'html-js-cors-plugin',
|
||||
options => {
|
||||
if (options.publicPath !== '/') {
|
||||
@@ -207,14 +207,14 @@ const CorsPlugin = {
|
||||
export function createHTMLPlugins(
|
||||
BUILD_CONFIG: BUILD_CONFIG_TYPE,
|
||||
config: CreateHTMLPluginConfig
|
||||
): (HTMLPlugin | PluginLike)[] {
|
||||
): (HtmlRspackPluginInstance | PluginLike)[] {
|
||||
const publicPath = getPublicPath(BUILD_CONFIG);
|
||||
const htmlPluginOptions = getHTMLPluginOptions(BUILD_CONFIG);
|
||||
const selfhostPublicPath = config.selfhostPublicPath ?? '/';
|
||||
|
||||
const plugins: (HTMLPlugin | PluginLike)[] = [];
|
||||
const plugins: (HtmlRspackPluginInstance | PluginLike)[] = [];
|
||||
plugins.push(
|
||||
new HTMLPlugin({
|
||||
new HtmlRspackPlugin({
|
||||
...htmlPluginOptions,
|
||||
chunks: ['index'],
|
||||
filename: config.filename,
|
||||
@@ -227,7 +227,7 @@ export function createHTMLPlugins(
|
||||
|
||||
if (BUILD_CONFIG.isElectron) {
|
||||
plugins.push(
|
||||
new HTMLPlugin({
|
||||
new HtmlRspackPlugin({
|
||||
...htmlPluginOptions,
|
||||
chunks: ['shell'],
|
||||
filename: 'shell.html',
|
||||
@@ -236,7 +236,7 @@ export function createHTMLPlugins(
|
||||
'env:publicPath': publicPath,
|
||||
},
|
||||
}),
|
||||
new HTMLPlugin({
|
||||
new HtmlRspackPlugin({
|
||||
...htmlPluginOptions,
|
||||
filename: 'popup.html',
|
||||
chunks: ['popup'],
|
||||
@@ -245,7 +245,7 @@ export function createHTMLPlugins(
|
||||
'env:publicPath': publicPath,
|
||||
},
|
||||
}),
|
||||
new HTMLPlugin({
|
||||
new HtmlRspackPlugin({
|
||||
...htmlPluginOptions,
|
||||
filename: 'background-worker.html',
|
||||
chunks: ['backgroundWorker'],
|
||||
@@ -271,7 +271,7 @@ export function createHTMLPlugins(
|
||||
|
||||
if (config.additionalEntryForSelfhost) {
|
||||
plugins.push(
|
||||
new HTMLPlugin({
|
||||
new HtmlRspackPlugin({
|
||||
...htmlPluginOptions,
|
||||
chunks: ['index'],
|
||||
publicPath: selfhostPublicPath,
|
||||
|
||||
@@ -124,8 +124,6 @@ export function createHTMLTargetConfig(
|
||||
dependencies: deps,
|
||||
context: ProjectRoot.value,
|
||||
experiments: {
|
||||
topLevelAwait: true,
|
||||
outputModule: false,
|
||||
asyncWebAssembly: true,
|
||||
},
|
||||
entry,
|
||||
@@ -364,7 +362,6 @@ export function createHTMLTargetConfig(
|
||||
providedExports: true,
|
||||
usedExports: true,
|
||||
sideEffects: true,
|
||||
removeAvailableModules: true,
|
||||
runtimeChunk: { name: 'runtime' },
|
||||
splitChunks: {
|
||||
chunks: 'all',
|
||||
@@ -426,8 +423,6 @@ export function createWorkerTargetConfig(
|
||||
name: entry,
|
||||
context: ProjectRoot.value,
|
||||
experiments: {
|
||||
topLevelAwait: true,
|
||||
outputModule: false,
|
||||
asyncWebAssembly: true,
|
||||
},
|
||||
entry: { [workerName]: entry },
|
||||
@@ -530,7 +525,6 @@ export function createWorkerTargetConfig(
|
||||
providedExports: true,
|
||||
usedExports: true,
|
||||
sideEffects: true,
|
||||
removeAvailableModules: true,
|
||||
runtimeChunk: false,
|
||||
splitChunks: false,
|
||||
},
|
||||
@@ -556,8 +550,6 @@ export function createNodeTargetConfig(
|
||||
name: entry,
|
||||
context: ProjectRoot.value,
|
||||
experiments: {
|
||||
topLevelAwait: true,
|
||||
outputModule: pkg.packageJson.type === 'module',
|
||||
asyncWebAssembly: true,
|
||||
},
|
||||
entry: { index: entry },
|
||||
@@ -566,6 +558,7 @@ export function createNodeTargetConfig(
|
||||
path: pkg.distPath.value,
|
||||
clean: true,
|
||||
globalObject: 'globalThis',
|
||||
module: pkg.packageJson.type === 'module',
|
||||
...(options.libraryType
|
||||
? { library: { type: options.libraryType } }
|
||||
: {}),
|
||||
|
||||
Reference in New Issue
Block a user