mirror of https://github.com/alibaba/ice.git
fix: compatible with plugin API configureWebpack in speedup mode (#6564)
This commit is contained in:
parent
50efd1ee95
commit
ca14f6d367
|
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
'@ice/webpack-config': patch
|
||||
'@ice/rspack-config': patch
|
||||
'@ice/shared-config': patch
|
||||
'@ice/app': patch
|
||||
---
|
||||
|
||||
fix: compatible with configureWebpack in speedup mode
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
import getRspackConfig from '@ice/rspack-config';
|
||||
import type { Configuration } from '@rspack/core';
|
||||
import type { rspack as Rspack } from '@ice/bundles/esm/rspack.js';
|
||||
import type { Config } from '@ice/shared-config/types';
|
||||
import { getRouteExportConfig } from '../../service/config.js';
|
||||
import {
|
||||
|
|
@ -16,10 +17,11 @@ import type { BundlerOptions, Context } from '../types.js';
|
|||
|
||||
type GetConfig = (
|
||||
context: Context,
|
||||
options: BundlerOptions
|
||||
options: BundlerOptions,
|
||||
rspack: typeof Rspack,
|
||||
) => Promise<Configuration[]>;
|
||||
|
||||
const getConfig: GetConfig = async (context, options) => {
|
||||
const getConfig: GetConfig = async (context, options, rspack) => {
|
||||
const {
|
||||
taskConfigs,
|
||||
spinner,
|
||||
|
|
@ -73,6 +75,7 @@ const getConfig: GetConfig = async (context, options) => {
|
|||
const plugins = getPlugins(config);
|
||||
return getRspackConfig({
|
||||
rootDir,
|
||||
rspack,
|
||||
runtimeTmpDir: RUNTIME_TMP_DIR,
|
||||
runtimeDefineVars: {
|
||||
[IMPORT_META_TARGET]: JSON.stringify(config.target),
|
||||
|
|
|
|||
|
|
@ -17,12 +17,11 @@ async function bundler(
|
|||
routeManifest,
|
||||
appConfig,
|
||||
} = options;
|
||||
const rspackConfigs = await getConfig(context, options);
|
||||
|
||||
let compiler: MultiCompiler;
|
||||
let devServer: RspackDevServer;
|
||||
const { rspack } = await import('@ice/bundles/esm/rspack.js');
|
||||
const rspackConfigs = await getConfig(context, options, rspack);
|
||||
try {
|
||||
const { rspack } = await import('@ice/bundles/esm/rspack.js');
|
||||
compiler = rspack(rspackConfigs);
|
||||
} catch (error) {
|
||||
logger.error('Webpack compile error.');
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import * as path from 'path';
|
||||
import { createRequire } from 'module';
|
||||
import { compilationPlugin, compileExcludes, getDefineVars } from '@ice/shared-config';
|
||||
import type { Config } from '@ice/shared-config/types';
|
||||
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';
|
||||
import AssetManifest from './plugins/AssetManifest.js';
|
||||
import getSplitChunks from './splitChunks.js';
|
||||
import getAssetsRule from './assetsRule.js';
|
||||
|
|
@ -16,6 +17,7 @@ interface GetRspackConfigOptions {
|
|||
runtimeDefineVars?: Record<string, any>;
|
||||
getRoutesFile?: () => string[];
|
||||
localIdentName?: string;
|
||||
rspack: typeof Rspack;
|
||||
}
|
||||
|
||||
type GetConfig = (
|
||||
|
|
@ -33,6 +35,7 @@ const getConfig: GetConfig = (options) => {
|
|||
runtimeDefineVars,
|
||||
getRoutesFile,
|
||||
localIdentName,
|
||||
rspack,
|
||||
} = options;
|
||||
|
||||
const {
|
||||
|
|
@ -55,6 +58,7 @@ const getConfig: GetConfig = (options) => {
|
|||
devServer = {},
|
||||
plugins = [],
|
||||
middlewares,
|
||||
configureWebpack = [],
|
||||
} = taskConfig || {};
|
||||
const absoluteOutputDir = path.isAbsolute(outputDir) ? outputDir : path.join(rootDir, outputDir);
|
||||
const hashKey = hash === true ? 'hash:8' : (hash || '');
|
||||
|
|
@ -165,7 +169,16 @@ const getConfig: GetConfig = (options) => {
|
|||
setupMiddlewares: middlewares,
|
||||
},
|
||||
};
|
||||
return config;
|
||||
// Compatible with API configureWebpack.
|
||||
const ctx = {
|
||||
...taskConfig,
|
||||
rootDir,
|
||||
hashKey,
|
||||
enableRpx2Vw,
|
||||
bundler: rspack,
|
||||
};
|
||||
return (configureWebpack as unknown as ModifyWebpackConfig<Configuration, typeof Rspack>[])
|
||||
.reduce((rspackConfig, next) => next(rspackConfig, ctx), config);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,11 @@ export type MinimizerOptions<T> = PredefinedOptions & InferDefaultType<T>;
|
|||
interface ConfigurationCtx<T = typeof webpack> extends Config {
|
||||
hashKey: string;
|
||||
enableRpx2Vw: boolean;
|
||||
webpack: T;
|
||||
/**
|
||||
* @deprecated Access bundler instance via `ctx.bundler` instead.
|
||||
*/
|
||||
webpack?: T;
|
||||
bundler?: T;
|
||||
rootDir: string;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -426,6 +426,7 @@ export function getWebpackConfig(options: GetWebpackConfigOptions): Configuratio
|
|||
rootDir,
|
||||
hashKey,
|
||||
webpack,
|
||||
bundler: webpack,
|
||||
enableRpx2Vw,
|
||||
};
|
||||
return [configCss, configAssets, ...(configureWebpack || [])]
|
||||
|
|
|
|||
Loading…
Reference in New Issue