Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 9 additions & 5 deletions packages/ice/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,20 +241,24 @@ const userConfig = [
{
name: 'compileDependencies',
validation: 'array|boolean',
getDefaultValue: () => (process.env.NODE_ENV === 'development' ? false : [/node_modules\/*/]),
setConfig: (config: Config, customValue: UserConfig['compileDependencies']) => {
let compileRegex: RegExp | false;
getDefaultValue: () => (process.env.NODE_ENV !== 'development'),
setConfig: (config: Config, customValue: UserConfig['compileDependencies'], context: UserConfigContext) => {
const speedupMode = context.commandArgs.speedup;
let compileRegex: RegExp | string | false;
if (customValue === true) {
compileRegex = /node_modules\/*/;
compileRegex = speedupMode ? 'node_modules' : /node_modules\/*/;
} else if (customValue && customValue.length > 0) {
compileRegex = new RegExp(
customValue
.map((dep: string | RegExp) => {
if (dep instanceof RegExp) {
if (speedupMode) {
throw new Error('speedup mode does not support config compileDependencies as RegExp');
}
return dep.source;
} else if (typeof dep === 'string') {
// add default prefix of node_modules
const matchStr = `node_modules/?.+${dep}/`;
const matchStr = speedupMode ? dep : `node_modules/?.+${dep}/`;
return matchStr;
}
return false;
Expand Down
38 changes: 20 additions & 18 deletions packages/rspack-config/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';
import { createRequire } from 'module';
import { compilationPlugin, compileExcludes, getDefineVars, getCompilerPlugins, getJsxTransformOptions, getAliasWithRoot } from '@ice/shared-config';
import { getDefineVars, getCompilerPlugins, getJsxTransformOptions, getAliasWithRoot, skipCompilePackages } from '@ice/shared-config';
import type { Config, ModifyWebpackConfig } from '@ice/shared-config/types';
import type { Configuration, rspack as Rspack } from '@rspack/core';
import lodash from '@ice/bundles/compiled/lodash/index.js';
Expand Down Expand Up @@ -52,9 +52,7 @@ const getConfig: GetConfig = async (options) => {
mode,
minify,
publicPath = '/',
cacheDir,
outputDir = 'build',
sourceMap,
externals = {},
alias = {},
compileIncludes,
Expand All @@ -75,19 +73,6 @@ const getConfig: GetConfig = async (options) => {
const isDev = mode === 'development';
const absoluteOutputDir = path.isAbsolute(outputDir) ? outputDir : path.join(rootDir, outputDir);
const hashKey = hash === true ? 'hash:8' : (hash || '');
const compilation = compilationPlugin({
rootDir,
cacheDir,
sourceMap,
fastRefresh: false,
mode,
compileIncludes,
compileExcludes,
swcOptions,
polyfill,
enableEnv: true,
getRoutesFile,
});

const { rspack: { DefinePlugin, ProvidePlugin, SwcJsMinimizerRspackPlugin } } = await import('@ice/bundles/esm/rspack.js');
const cssFilename = `css/${hashKey ? `[name]-[${hashKey}].css` : '[name].css'}`;
Expand Down Expand Up @@ -128,6 +113,19 @@ const getConfig: GetConfig = async (options) => {
? splitChunks
: getSplitChunks(rootDir, splitChunks);
}
// Get built-in exclude packages.
const compileExclude = skipCompilePackages.map((pkg) => {
return `node_modules[\\/](${pkg}[\\/]|_${pkg.replace('/', '_')}@[^/]+[\\/])`;
});
let excludeRule: string;

if (!compileIncludes || compileIncludes?.length === 0) {
excludeRule = 'node_modules';
} else if (!compileIncludes?.includes('node_modules') && compileIncludes?.length > 0) {
excludeRule = `node_modules[\\/](?!${compileIncludes.map((pkg: string) => {
return `${pkg}[\\/]|_${pkg.replace('/', '_')}@[^/]+[\\/]`;
}).join('|')}).*`;
}
const config: Configuration = {
entry: {
main: [path.join(rootDir, runtimeTmpDir, 'entry.client.tsx')],
Expand All @@ -148,8 +146,8 @@ const getConfig: GetConfig = async (options) => {
module: {
rules: [
{
// TODO: use regexp to improve performance.
test: compilation.transformInclude,
test: /\.(jsx?|tsx?|mjs)$/,
...(excludeRule ? { exclude: new RegExp(excludeRule) } : {}),
use: {
loader: 'builtin:compilation-loader',
options: {
Expand All @@ -158,6 +156,10 @@ const getConfig: GetConfig = async (options) => {
removeExport: swcOptions.removeExportExprs,
keepExport: swcOptions.keepExports,
},
compileRules: {
// "bundles/compiled" is the path when using @ice/bundles.
exclude: [...compileExclude, 'bundles/compiled'],
},
},
},
},
Expand Down