mirror of https://github.com/alibaba/ice.git
fix: support transform plugin in speedup mode (#6615)
* fix: support tranform plugin in speedup mode * chore: lint * chore: remove log
This commit is contained in:
parent
81849becf8
commit
d4aaa5806b
|
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
'@ice/rspack-config': patch
|
||||
'@ice/shared-config': patch
|
||||
'@ice/bundles': patch
|
||||
'@ice/app': patch
|
||||
---
|
||||
|
||||
fix: support custom transform plugins in speedup mode
|
||||
|
|
@ -71,7 +71,7 @@
|
|||
"webpack": "5.88.2",
|
||||
"webpack-bundle-analyzer": "4.5.0",
|
||||
"webpack-dev-server": "4.15.0",
|
||||
"unplugin": "0.9.5",
|
||||
"unplugin": "1.5.0",
|
||||
"bonjour-service": "^1.0.13",
|
||||
"colorette": "^2.0.10",
|
||||
"compression": "^1.7.4",
|
||||
|
|
|
|||
|
|
@ -86,6 +86,22 @@ const tasks = [
|
|||
file: 'node_modules/unplugin/dist/webpack/loaders/load.js',
|
||||
bundleName: 'webpack/loaders/load.js',
|
||||
},
|
||||
{
|
||||
pkgName: 'unplugin',
|
||||
declaration: false,
|
||||
emptyDir: false,
|
||||
externals: taskExternals,
|
||||
file: 'node_modules/unplugin/dist/rspack/loaders/transform.js',
|
||||
bundleName: 'rspack/loaders/transform.js',
|
||||
},
|
||||
{
|
||||
pkgName: 'unplugin',
|
||||
declaration: false,
|
||||
emptyDir: false,
|
||||
externals: taskExternals,
|
||||
file: 'node_modules/unplugin/dist/rspack/loaders/load.js',
|
||||
bundleName: 'rspack/loaders/load.js',
|
||||
},
|
||||
{
|
||||
// pack main package
|
||||
pkgName: 'fork-ts-checker-webpack-plugin',
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@
|
|||
"react": "^18.2.0",
|
||||
"react-router": "6.14.2",
|
||||
"sass": "^1.50.0",
|
||||
"unplugin": "^0.9.0",
|
||||
"unplugin": "^1.5.0",
|
||||
"webpack": "^5.88.0",
|
||||
"webpack-dev-server": "^4.7.4",
|
||||
"@rspack/core": "0.3.0",
|
||||
|
|
@ -111,4 +111,4 @@
|
|||
"publishConfig": {
|
||||
"access": "public"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,13 @@
|
|||
import detectPort from 'detect-port';
|
||||
import type { CommandArgs } from 'build-scripts';
|
||||
import type { Configuration } from 'webpack-dev-server';
|
||||
import type { Configuration as DevServerConfiguration } from '@rspack/dev-server';
|
||||
import { DEFAULT_HOST, DEFAULT_PORT } from '../../constant.js';
|
||||
|
||||
async function getDefaultServerConfig(devServerConfig: Configuration, commandArgs: CommandArgs) {
|
||||
async function getDefaultServerConfig(
|
||||
devServerConfig: Configuration | DevServerConfiguration,
|
||||
commandArgs: CommandArgs,
|
||||
) {
|
||||
// Get the value of the host and port from the command line, environment variables, and webpack config.
|
||||
// Value priority: process.env.PORT > commandArgs > webpackConfig > DEFAULT.
|
||||
const host = process.env.HOST ||
|
||||
|
|
|
|||
|
|
@ -2,13 +2,15 @@ import type { TaskConfig } from 'build-scripts';
|
|||
import type { Config } from '@ice/shared-config/types';
|
||||
import type { AppConfig } from '@ice/runtime/types';
|
||||
import type { Configuration as DevServerConfiguration } from 'webpack-dev-server';
|
||||
import type { Configuration as RSPackDevServerConfiguration } from '@rspack/dev-server';
|
||||
|
||||
import prepareURLs from '../../utils/prepareURLs.js';
|
||||
import getRouterBasename from '../../utils/getRouterBasename.js';
|
||||
|
||||
interface Options {
|
||||
taskConfig: TaskConfig<Config>;
|
||||
appConfig: AppConfig;
|
||||
devServerConfig: DevServerConfiguration;
|
||||
devServerConfig: DevServerConfiguration | RSPackDevServerConfiguration;
|
||||
}
|
||||
|
||||
const getUrls = ({
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import * as path from 'path';
|
||||
import { createRequire } from 'module';
|
||||
import { compilationPlugin, compileExcludes, getDefineVars } from '@ice/shared-config';
|
||||
import { compilationPlugin, compileExcludes, getDefineVars, getCompilerPlugins } from '@ice/shared-config';
|
||||
import type { Config, ModifyWebpackConfig } from '@ice/shared-config/types';
|
||||
import type { Configuration } from '@rspack/core';
|
||||
import type { rspack as Rspack } from '@ice/bundles/esm/rspack.js';
|
||||
|
|
@ -76,6 +76,8 @@ const getConfig: GetConfig = (options) => {
|
|||
getRoutesFile,
|
||||
});
|
||||
const cssFilename = `css/${hashKey ? `[name]-[${hashKey}].css` : '[name].css'}`;
|
||||
// get compile plugins
|
||||
const compilerWebpackPlugins = getCompilerPlugins(rootDir, taskConfig || {}, 'rspack', { isServer: false });
|
||||
const config: Configuration = {
|
||||
entry: {
|
||||
main: [path.join(rootDir, runtimeTmpDir, 'entry.client.tsx')],
|
||||
|
|
@ -127,11 +129,13 @@ const getConfig: GetConfig = (options) => {
|
|||
},
|
||||
// @ts-expect-error plugin instance defined by default in not compatible with rspack.
|
||||
plugins: [
|
||||
...plugins,
|
||||
// Unplugin should be compatible with rspack.
|
||||
...compilerWebpackPlugins,
|
||||
new AssetManifest({
|
||||
fileName: 'assets-manifest.json',
|
||||
outputDir: path.join(rootDir, runtimeTmpDir),
|
||||
}),
|
||||
...plugins,
|
||||
].filter(Boolean),
|
||||
builtins: {
|
||||
define: getDefineVars(define, runtimeDefineVars, getExpandedEnvs),
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import compilationPlugin from './unPlugins/compilation.js';
|
|||
import redirectImportPlugin from './unPlugins/redirectImport.js';
|
||||
import compileExcludes from './compileExcludes.js';
|
||||
|
||||
type Compiler = 'webpack' | 'esbuild';
|
||||
type Compiler = 'webpack' | 'esbuild' | 'rspack';
|
||||
interface TransformOptions {
|
||||
isServer: boolean;
|
||||
}
|
||||
|
|
@ -31,6 +31,7 @@ function transformInclude(id: string) {
|
|||
return !!id.match(/\.(js|jsx|ts|tsx|mjs|mts|css|less|scss)$/);
|
||||
}
|
||||
|
||||
function getCompilerPlugins(rootDir: string, config: Config, compiler: 'rspack', transformOptions: TransformOptions): Config['plugins'];
|
||||
function getCompilerPlugins(rootDir: string, config: Config, compiler: 'webpack', transformOptions: TransformOptions): Config['plugins'];
|
||||
function getCompilerPlugins(rootDir: string, config: Config, compiler: 'esbuild', transformOptions: TransformOptions): BuildOptions['plugins'];
|
||||
function getCompilerPlugins(rootDir: string, config: Config, compiler: Compiler, transformOptions: TransformOptions) {
|
||||
|
|
@ -55,10 +56,10 @@ function getCompilerPlugins(rootDir: string, config: Config, compiler: Compiler,
|
|||
...(transformPlugins.filter(({ enforce }) => !enforce || enforce === 'pre') || []),
|
||||
...transforms.map((transform, index) => ({ name: `transform_${index}`, transform, transformInclude })),
|
||||
);
|
||||
|
||||
const clientBundlers = ['webpack', 'rspack'];
|
||||
// Use webpack loader instead of webpack plugin to do the compilation.
|
||||
// Reason: https://github.com/unjs/unplugin/issues/154
|
||||
if (swcOptions && compiler !== 'webpack') {
|
||||
if (swcOptions && !clientBundlers.includes(compiler)) {
|
||||
compilerPlugins.push(compilationPlugin({
|
||||
rootDir,
|
||||
cacheDir,
|
||||
|
|
@ -85,13 +86,14 @@ function getCompilerPlugins(rootDir: string, config: Config, compiler: Compiler,
|
|||
exportData: redirectImports,
|
||||
}));
|
||||
}
|
||||
|
||||
return compiler === 'webpack'
|
||||
// Plugins will be transformed as webpack loader, the execute order of webpack loader is reversed.
|
||||
? compilerPlugins
|
||||
.reverse()
|
||||
.map((plugin) => createUnplugin(() => getPluginTransform(plugin, transformOptions)).webpack()) as Config['plugins']
|
||||
: compilerPlugins.map(plugin => getPluginTransform(plugin, transformOptions));
|
||||
if (clientBundlers.includes(compiler)) {
|
||||
return compilerPlugins
|
||||
// Plugins will be transformed as webpack loader, the execute order of webpack loader is reversed.
|
||||
.reverse()
|
||||
.map((plugin) => createUnplugin(() => getPluginTransform(plugin, transformOptions))[compiler]()) as Config['plugins'];
|
||||
} else {
|
||||
return compilerPlugins.map(plugin => getPluginTransform(plugin, transformOptions));
|
||||
}
|
||||
}
|
||||
|
||||
export default getCompilerPlugins;
|
||||
|
|
|
|||
|
|
@ -1466,8 +1466,8 @@ importers:
|
|||
specifier: ^4.6.4
|
||||
version: 4.9.5
|
||||
unplugin:
|
||||
specifier: 0.9.5
|
||||
version: 0.9.5(esbuild@0.17.16)(webpack@5.88.2)
|
||||
specifier: 1.5.0
|
||||
version: 1.5.0
|
||||
webpack:
|
||||
specifier: 5.88.2
|
||||
version: 5.88.2(@swc/core@1.3.80)(esbuild@0.17.16)
|
||||
|
|
@ -1673,8 +1673,8 @@ importers:
|
|||
specifier: ^1.50.0
|
||||
version: 1.50.0
|
||||
unplugin:
|
||||
specifier: ^0.9.0
|
||||
version: 0.9.5(esbuild@0.17.16)(webpack@5.88.2)
|
||||
specifier: ^1.5.0
|
||||
version: 1.5.0
|
||||
webpack:
|
||||
specifier: ^5.88.0
|
||||
version: 5.88.2(esbuild@0.17.16)
|
||||
|
|
@ -9394,10 +9394,17 @@ packages:
|
|||
/acorn-globals@7.0.1:
|
||||
resolution: {integrity: sha512-umOSDSDrfHbTNPuNpC2NSnnA3LUrqpevPb4T9jRx4MagXNS0rs+gwiTcAvqCRmsD6utzsrzNt+ebm00SNWiC3Q==}
|
||||
dependencies:
|
||||
acorn: 8.8.2
|
||||
acorn: 8.11.2
|
||||
acorn-walk: 8.2.0
|
||||
dev: true
|
||||
|
||||
/acorn-import-assertions@1.9.0(acorn@8.11.2):
|
||||
resolution: {integrity: sha512-cmMwop9x+8KFhxvKrKfPYmN6/pKTYYHBqLa0DfvVZcKMJWNyWLnaqND7dx/qn66R7ewM1UX5XMaDVP5wlVTaVA==}
|
||||
peerDependencies:
|
||||
acorn: ^8
|
||||
dependencies:
|
||||
acorn: 8.11.2
|
||||
|
||||
/acorn-import-assertions@1.9.0(acorn@8.8.2):
|
||||
resolution: {integrity: sha512-cmMwop9x+8KFhxvKrKfPYmN6/pKTYYHBqLa0DfvVZcKMJWNyWLnaqND7dx/qn66R7ewM1UX5XMaDVP5wlVTaVA==}
|
||||
peerDependencies:
|
||||
|
|
@ -9405,12 +9412,12 @@ packages:
|
|||
dependencies:
|
||||
acorn: 8.8.2
|
||||
|
||||
/acorn-jsx@5.3.2(acorn@8.8.2):
|
||||
/acorn-jsx@5.3.2(acorn@8.11.2):
|
||||
resolution: {integrity: sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==}
|
||||
peerDependencies:
|
||||
acorn: ^6.0.0 || ^7.0.0 || ^8.0.0
|
||||
dependencies:
|
||||
acorn: 8.8.2
|
||||
acorn: 8.11.2
|
||||
|
||||
/acorn-node@1.8.2:
|
||||
resolution: {integrity: sha512-8mt+fslDufLYntIoPAaIMUe/lrbrehIiwmR3t2k9LljIzoigEPF27eLk2hy8zSGzmR/ogr7zbRKINMo1u0yh5A==}
|
||||
|
|
@ -9435,6 +9442,11 @@ packages:
|
|||
hasBin: true
|
||||
dev: true
|
||||
|
||||
/acorn@8.11.2:
|
||||
resolution: {integrity: sha512-nc0Axzp/0FILLEVsm4fNwLCwMttvhEI263QtVPQcbpfZZ3ts0hLsZGOpE6czNlid7CJ9MlyH8reXkpsf3YUY4w==}
|
||||
engines: {node: '>=0.4.0'}
|
||||
hasBin: true
|
||||
|
||||
/acorn@8.8.2:
|
||||
resolution: {integrity: sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw==}
|
||||
engines: {node: '>=0.4.0'}
|
||||
|
|
@ -13165,8 +13177,8 @@ packages:
|
|||
resolution: {integrity: sha512-XwctdmTO6SIvCzd9810yyNzIrOrqNYV9Koizx4C/mRhf9uq0o4yHoCEU/670pOxOL/MSraektvSAji79kX90Vg==}
|
||||
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
|
||||
dependencies:
|
||||
acorn: 8.8.2
|
||||
acorn-jsx: 5.3.2(acorn@8.8.2)
|
||||
acorn: 8.11.2
|
||||
acorn-jsx: 5.3.2(acorn@8.11.2)
|
||||
eslint-visitor-keys: 3.3.0
|
||||
|
||||
/esprima@4.0.1:
|
||||
|
|
@ -21429,7 +21441,7 @@ packages:
|
|||
/strip-literal@0.4.2:
|
||||
resolution: {integrity: sha512-pv48ybn4iE1O9RLgCAN0iU4Xv7RlBTiit6DKmMiErbs9x1wH6vXBs45tWc0H5wUIF6TLTrKweqkmYF/iraQKNw==}
|
||||
dependencies:
|
||||
acorn: 8.8.2
|
||||
acorn: 8.11.2
|
||||
dev: true
|
||||
|
||||
/style-equal@1.0.0:
|
||||
|
|
@ -21958,7 +21970,7 @@ packages:
|
|||
hasBin: true
|
||||
dependencies:
|
||||
'@jridgewell/source-map': 0.3.2
|
||||
acorn: 8.8.2
|
||||
acorn: 8.11.2
|
||||
commander: 2.20.3
|
||||
source-map-support: 0.5.21
|
||||
|
||||
|
|
@ -22189,7 +22201,7 @@ packages:
|
|||
'@tsconfig/node14': 1.0.3
|
||||
'@tsconfig/node16': 1.0.3
|
||||
'@types/node': 17.0.45
|
||||
acorn: 8.8.2
|
||||
acorn: 8.11.2
|
||||
acorn-walk: 8.2.0
|
||||
arg: 4.1.3
|
||||
create-require: 1.1.1
|
||||
|
|
@ -22597,29 +22609,13 @@ packages:
|
|||
resolution: {integrity: sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==}
|
||||
engines: {node: '>= 0.8'}
|
||||
|
||||
/unplugin@0.9.5(esbuild@0.17.16)(webpack@5.88.2):
|
||||
resolution: {integrity: sha512-luraheyfxwtvkvHpsOvMNv7IjLdORTWKZp0gWYNHGLi2ImON3iIZOj464qEyyEwLA/EMt12fC415HW9zRpOfTg==}
|
||||
peerDependencies:
|
||||
esbuild: '>=0.13'
|
||||
rollup: ^2.50.0
|
||||
vite: ^2.3.0 || ^3.0.0-0
|
||||
webpack: 4 || 5
|
||||
peerDependenciesMeta:
|
||||
esbuild:
|
||||
optional: true
|
||||
rollup:
|
||||
optional: true
|
||||
vite:
|
||||
optional: true
|
||||
webpack:
|
||||
optional: true
|
||||
/unplugin@1.5.0:
|
||||
resolution: {integrity: sha512-9ZdRwbh/4gcm1JTOkp9lAkIDrtOyOxgHmY7cjuwI8L/2RTikMcVG25GsZwNAgRuap3iDw2jeq7eoqtAsz5rW3A==}
|
||||
dependencies:
|
||||
acorn: 8.8.2
|
||||
acorn: 8.11.2
|
||||
chokidar: 3.5.3
|
||||
esbuild: 0.17.16
|
||||
webpack: 5.88.2(@swc/core@1.3.80)(esbuild@0.17.16)
|
||||
webpack-sources: 3.2.3
|
||||
webpack-virtual-modules: 0.4.6
|
||||
webpack-virtual-modules: 0.5.0
|
||||
dev: true
|
||||
|
||||
/unquote@1.1.1:
|
||||
|
|
@ -23102,7 +23098,7 @@ packages:
|
|||
hasBin: true
|
||||
dependencies:
|
||||
'@discoveryjs/json-ext': 0.5.7
|
||||
acorn: 8.8.2
|
||||
acorn: 8.11.2
|
||||
acorn-walk: 8.2.0
|
||||
chalk: 4.1.2
|
||||
commander: 7.2.0
|
||||
|
|
@ -23491,8 +23487,8 @@ packages:
|
|||
resolution: {integrity: sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==}
|
||||
engines: {node: '>=10.13.0'}
|
||||
|
||||
/webpack-virtual-modules@0.4.6:
|
||||
resolution: {integrity: sha512-5tyDlKLqPfMqjT3Q9TAqf2YqjwmnUleZwzJi1A5qXnlBCdj2AtOJ6wAWdglTIDOPgOiOrXeBeFcsQ8+aGQ6QbA==}
|
||||
/webpack-virtual-modules@0.5.0:
|
||||
resolution: {integrity: sha512-kyDivFZ7ZM0BVOUteVbDFhlRt7Ah/CSPwJdi8hBpkK7QLumUqdLtVfm/PX/hkcnrvr0i77fO5+TjZ94Pe+C9iw==}
|
||||
dev: true
|
||||
|
||||
/webpack@5.76.0(@swc/core@1.3.80)(esbuild@0.17.16):
|
||||
|
|
@ -23510,8 +23506,8 @@ packages:
|
|||
'@webassemblyjs/ast': 1.11.1
|
||||
'@webassemblyjs/wasm-edit': 1.11.1
|
||||
'@webassemblyjs/wasm-parser': 1.11.1
|
||||
acorn: 8.8.2
|
||||
acorn-import-assertions: 1.9.0(acorn@8.8.2)
|
||||
acorn: 8.11.2
|
||||
acorn-import-assertions: 1.9.0(acorn@8.11.2)
|
||||
browserslist: 4.21.5
|
||||
chrome-trace-event: 1.0.3
|
||||
enhanced-resolve: 5.15.0
|
||||
|
|
@ -23549,8 +23545,8 @@ packages:
|
|||
'@webassemblyjs/ast': 1.11.1
|
||||
'@webassemblyjs/wasm-edit': 1.11.1
|
||||
'@webassemblyjs/wasm-parser': 1.11.1
|
||||
acorn: 8.8.2
|
||||
acorn-import-assertions: 1.9.0(acorn@8.8.2)
|
||||
acorn: 8.11.2
|
||||
acorn-import-assertions: 1.9.0(acorn@8.11.2)
|
||||
browserslist: 4.21.5
|
||||
chrome-trace-event: 1.0.3
|
||||
enhanced-resolve: 5.15.0
|
||||
|
|
|
|||
Loading…
Reference in New Issue