mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-12 23:56:36 +08:00
feat: cleanup webpack deps (#14530)
#### PR Dependency Tree * **PR #14530** 👈 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 * **Breaking Changes** * Webpack bundler support removed from the build system * Bundler selection parameter removed from build and development commands * **Refactor** * Build configuration consolidated to a single bundler approach * Webpack-specific build paths and workflows removed; development server simplified * **Chores** * Removed webpack-related dev dependencies and tooling * Updated package build scripts for a unified bundle command * **Dependencies** * Upgraded Sentry packages across frontend packages (react/electron/esbuild plugin) <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -7,21 +7,51 @@ import { Package } from '@affine-tools/utils/workspace';
|
||||
import rspack, {
|
||||
type Configuration as RspackConfiguration,
|
||||
} from '@rspack/core';
|
||||
import { sentryWebpackPlugin } from '@sentry/webpack-plugin';
|
||||
import type { sentryWebpackPlugin as SentryWebpackPluginFactory } from '@sentry/webpack-plugin';
|
||||
import { VanillaExtractPlugin } from '@vanilla-extract/webpack-plugin';
|
||||
import cssnano from 'cssnano';
|
||||
import { compact, merge } from 'lodash-es';
|
||||
|
||||
import { queuedashScopePostcssPlugin } from '../postcss/queuedash-scope.js';
|
||||
import { productionCacheGroups } from '../webpack/cache-group.js';
|
||||
import { productionCacheGroups } from '../rspack-shared/cache-group.js';
|
||||
import {
|
||||
type CreateHTMLPluginConfig,
|
||||
createHTMLPlugins as createWebpackCompatibleHTMLPlugins,
|
||||
} from '../webpack/html-plugin.js';
|
||||
createHTMLPlugins,
|
||||
} from '../rspack-shared/html-plugin.js';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
const IN_CI = !!process.env.CI;
|
||||
const hasSentryBuildEnvs = () =>
|
||||
!!(
|
||||
process.env.SENTRY_AUTH_TOKEN &&
|
||||
process.env.SENTRY_ORG &&
|
||||
process.env.SENTRY_PROJECT
|
||||
);
|
||||
|
||||
function createSentryPlugin() {
|
||||
if (!hasSentryBuildEnvs()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const { sentryWebpackPlugin } = require('@sentry/webpack-plugin') as {
|
||||
sentryWebpackPlugin: typeof SentryWebpackPluginFactory;
|
||||
};
|
||||
|
||||
return sentryWebpackPlugin({
|
||||
org: process.env.SENTRY_ORG!,
|
||||
project: process.env.SENTRY_PROJECT!,
|
||||
authToken: process.env.SENTRY_AUTH_TOKEN!,
|
||||
});
|
||||
} catch (error) {
|
||||
const reason =
|
||||
error instanceof Error ? error.message : 'unknown load error';
|
||||
throw new Error(
|
||||
`Failed to load @sentry/webpack-plugin while SENTRY_* envs are set: ${reason}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const availableChannels = ['canary', 'beta', 'stable', 'internal'];
|
||||
function getBuildConfigFromEnv(pkg: Package) {
|
||||
@@ -73,7 +103,7 @@ export function createHTMLTargetConfig(
|
||||
console.log(`Config: ${JSON.stringify(buildConfig, null, 2)}`);
|
||||
|
||||
const config: RspackConfiguration = {
|
||||
//#region basic webpack config
|
||||
//#region basic bundler config
|
||||
name: entry['index'],
|
||||
dependencies: deps,
|
||||
context: ProjectRoot.value,
|
||||
@@ -253,7 +283,7 @@ export function createHTMLTargetConfig(
|
||||
//#region plugins
|
||||
plugins: compact([
|
||||
!IN_CI && new rspack.ProgressPlugin(),
|
||||
...createWebpackCompatibleHTMLPlugins(buildConfig, htmlConfig),
|
||||
...createHTMLPlugins(buildConfig, htmlConfig),
|
||||
new rspack.DefinePlugin({
|
||||
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
||||
...Object.entries(buildConfig).reduce(
|
||||
@@ -280,14 +310,7 @@ export function createHTMLTargetConfig(
|
||||
},
|
||||
],
|
||||
}),
|
||||
process.env.SENTRY_AUTH_TOKEN &&
|
||||
process.env.SENTRY_ORG &&
|
||||
process.env.SENTRY_PROJECT &&
|
||||
sentryWebpackPlugin({
|
||||
org: process.env.SENTRY_ORG,
|
||||
project: process.env.SENTRY_PROJECT,
|
||||
authToken: process.env.SENTRY_AUTH_TOKEN,
|
||||
}),
|
||||
createSentryPlugin(),
|
||||
// sourcemap url like # sourceMappingURL=76-6370cd185962bc89.js.map wont load in electron
|
||||
// this is because the default file:// protocol will be ignored by Chromium
|
||||
// so we need to replace the sourceMappingURL to assets:// protocol
|
||||
@@ -470,14 +493,7 @@ export function createWorkerTargetConfig(
|
||||
)
|
||||
),
|
||||
new rspack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }),
|
||||
process.env.SENTRY_AUTH_TOKEN &&
|
||||
process.env.SENTRY_ORG &&
|
||||
process.env.SENTRY_PROJECT &&
|
||||
sentryWebpackPlugin({
|
||||
org: process.env.SENTRY_ORG,
|
||||
project: process.env.SENTRY_PROJECT,
|
||||
authToken: process.env.SENTRY_AUTH_TOKEN,
|
||||
}),
|
||||
createSentryPlugin(),
|
||||
]),
|
||||
stats: { errorDetails: true },
|
||||
optimization: {
|
||||
@@ -506,9 +522,18 @@ export function createWorkerTargetConfig(
|
||||
|
||||
export function createNodeTargetConfig(
|
||||
pkg: Package,
|
||||
entry: string
|
||||
entry: string,
|
||||
options: {
|
||||
outputFilename?: string;
|
||||
decoratorVersion?: 'legacy' | '2022-03';
|
||||
libraryType?: 'module' | 'commonjs2';
|
||||
bundleAllDependencies?: boolean;
|
||||
forceExternal?: string[];
|
||||
} = {}
|
||||
): Omit<RspackConfiguration, 'name'> & { name: string } {
|
||||
const dev = process.env.NODE_ENV === 'development';
|
||||
const useLegacyDecorator = options.decoratorVersion !== '2022-03';
|
||||
const forceExternal = options.forceExternal ?? [];
|
||||
return {
|
||||
name: entry,
|
||||
context: ProjectRoot.value,
|
||||
@@ -519,17 +544,28 @@ export function createNodeTargetConfig(
|
||||
},
|
||||
entry: { index: entry },
|
||||
output: {
|
||||
filename: `main.js`,
|
||||
filename: options.outputFilename ?? 'main.js',
|
||||
path: pkg.distPath.value,
|
||||
clean: true,
|
||||
globalObject: 'globalThis',
|
||||
...(options.libraryType
|
||||
? { library: { type: options.libraryType } }
|
||||
: {}),
|
||||
},
|
||||
target: ['node', 'es2022'],
|
||||
externals: ((data: any, callback: (err: null, value: boolean) => void) => {
|
||||
if (
|
||||
data.request &&
|
||||
forceExternal.some(
|
||||
dep => data.request === dep || data.request.startsWith(`${dep}/`)
|
||||
)
|
||||
) {
|
||||
callback(null, true);
|
||||
} else if (
|
||||
data.request &&
|
||||
// import ... from 'module'
|
||||
/^[a-zA-Z@]/.test(data.request) &&
|
||||
!options.bundleAllDependencies &&
|
||||
// not workspace deps
|
||||
!pkg.deps.some(dep => data.request!.startsWith(dep.name))
|
||||
) {
|
||||
@@ -561,8 +597,9 @@ export function createNodeTargetConfig(
|
||||
},
|
||||
{
|
||||
test: /\.node$/,
|
||||
loader: Path.dir(import.meta.url).join('../webpack/node-loader.js')
|
||||
.value,
|
||||
loader: Path.dir(import.meta.url).join(
|
||||
'../rspack-shared/node-loader.js'
|
||||
).value,
|
||||
},
|
||||
{
|
||||
test: /\.tsx?$/,
|
||||
@@ -582,8 +619,15 @@ export function createNodeTargetConfig(
|
||||
target: 'es2022',
|
||||
externalHelpers: false,
|
||||
transform: {
|
||||
legacyDecorator: true,
|
||||
decoratorMetadata: true,
|
||||
...(useLegacyDecorator
|
||||
? {
|
||||
legacyDecorator: true,
|
||||
decoratorMetadata: true,
|
||||
}
|
||||
: {
|
||||
useDefineForClassFields: false,
|
||||
decoratorVersion: '2022-03',
|
||||
}),
|
||||
react: { runtime: 'automatic' },
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user