11import * as path from 'path' ;
22import { createRequire } from 'module' ;
3- import { compilationPlugin , compileExcludes , getDefineVars , getCompilerPlugins , getJsxTransformOptions , getAliasWithRoot } from '@ice/shared-config' ;
3+ import { getDefineVars , getCompilerPlugins , getJsxTransformOptions , getAliasWithRoot , skipCompilePackages } from '@ice/shared-config' ;
44import type { Config , ModifyWebpackConfig } from '@ice/shared-config/types' ;
55import type { Configuration , rspack as Rspack } from '@rspack/core' ;
66import lodash from '@ice/bundles/compiled/lodash/index.js' ;
@@ -52,9 +52,7 @@ const getConfig: GetConfig = async (options) => {
5252 mode,
5353 minify,
5454 publicPath = '/' ,
55- cacheDir,
5655 outputDir = 'build' ,
57- sourceMap,
5856 externals = { } ,
5957 alias = { } ,
6058 compileIncludes,
@@ -75,19 +73,6 @@ const getConfig: GetConfig = async (options) => {
7573 const isDev = mode === 'development' ;
7674 const absoluteOutputDir = path . isAbsolute ( outputDir ) ? outputDir : path . join ( rootDir , outputDir ) ;
7775 const hashKey = hash === true ? 'hash:8' : ( hash || '' ) ;
78- const compilation = compilationPlugin ( {
79- rootDir,
80- cacheDir,
81- sourceMap,
82- fastRefresh : false ,
83- mode,
84- compileIncludes,
85- compileExcludes,
86- swcOptions,
87- polyfill,
88- enableEnv : true ,
89- getRoutesFile,
90- } ) ;
9176
9277 const { rspack : { DefinePlugin, ProvidePlugin, SwcJsMinimizerRspackPlugin } } = await import ( '@ice/bundles/esm/rspack.js' ) ;
9378 const cssFilename = `css/${ hashKey ? `[name]-[${ hashKey } ].css` : '[name].css' } ` ;
@@ -128,6 +113,19 @@ const getConfig: GetConfig = async (options) => {
128113 ? splitChunks
129114 : getSplitChunks ( rootDir , splitChunks ) ;
130115 }
116+ // Get built-in exclude packages.
117+ const compileExclude = skipCompilePackages . map ( ( pkg ) => {
118+ return `node_modules[\\/](${ pkg } [\\/]|_${ pkg . replace ( '/' , '_' ) } @[^/]+[\\/])` ;
119+ } ) ;
120+ let excludeRule : string ;
121+
122+ if ( ! compileIncludes || compileIncludes ?. length === 0 ) {
123+ excludeRule = 'node_modules' ;
124+ } else if ( ! compileIncludes ?. includes ( 'node_modules' ) && compileIncludes ?. length > 0 ) {
125+ excludeRule = `node_modules[\\/](?!${ compileIncludes . map ( ( pkg : string ) => {
126+ return `${ pkg } [\\/]|_${ pkg . replace ( '/' , '_' ) } @[^/]+[\\/]` ;
127+ } ) . join ( '|' ) } ).*`;
128+ }
131129 const config : Configuration = {
132130 entry : {
133131 main : [ path . join ( rootDir , runtimeTmpDir , 'entry.client.tsx' ) ] ,
@@ -148,8 +146,8 @@ const getConfig: GetConfig = async (options) => {
148146 module : {
149147 rules : [
150148 {
151- // TODO: use regexp to improve performance.
152- test : compilation . transformInclude ,
149+ test : / \. ( j s x ? | t s x ? | m j s ) $ / ,
150+ ... ( excludeRule ? { exclude : new RegExp ( excludeRule ) } : { } ) ,
153151 use : {
154152 loader : 'builtin:compilation-loader' ,
155153 options : {
@@ -158,6 +156,10 @@ const getConfig: GetConfig = async (options) => {
158156 removeExport : swcOptions . removeExportExprs ,
159157 keepExport : swcOptions . keepExports ,
160158 } ,
159+ compileRules : {
160+ // "bundles/compiled" is the path when using @ice/bundles.
161+ exclude : [ ...compileExclude , 'bundles/compiled' ] ,
162+ } ,
161163 } ,
162164 } ,
163165 } ,
0 commit comments