diff --git a/docs/docs/rspack/node-externals.mdx b/docs/docs/rspack/node-externals.mdx index 01aaf19..b1a0446 100644 --- a/docs/docs/rspack/node-externals.mdx +++ b/docs/docs/rspack/node-externals.mdx @@ -32,6 +32,10 @@ export default { }; ``` +### Option `importType` + +Tells Rspack how to import external dependency. By default it is `module`. + ### Option `allow` To force add some dependencies to bundle you can use `allow` option: @@ -42,4 +46,6 @@ nodeExternals({ }); ``` -By default it contains `css-loader` because it injects some code into runtime. +By default `css-loader` and `*.css` files allowed. +Files from `css-loader` allowed because it injects some code into runtime. +CSS files allowed to easy use styles from libraries like `overlay-scrollbars` or `@krutoo/showcase`. diff --git a/docs/rspack.config.ts b/docs/rspack.config.ts index 5110fb3..21a7489 100644 --- a/docs/rspack.config.ts +++ b/docs/rspack.config.ts @@ -42,10 +42,7 @@ export default [ module: true, }, devtool: isProd ? false : undefined, - externals: utils.nodeExternals({ - importType: 'module', - allow: [/css-loader/, /\.css$/i], - }), + externals: utils.nodeExternals(), externalsPresets: { node: true, }, diff --git a/src/rspack/node-externals.ts b/src/rspack/node-externals.ts index 4838bc9..2295a0b 100644 --- a/src/rspack/node-externals.ts +++ b/src/rspack/node-externals.ts @@ -8,24 +8,36 @@ export type AllowlistItemFunction = (request: string) => boolean; export type AllowlistItem = string | RegExp | AllowlistItemFunction; export interface NodeExternalsOptions { - /** Method of importing requested module. */ + /** + * Method of importing requested module. + * @default `module` + */ importType?: ExternalsType; - /** Defines modules that should be included to bundle. */ + /** + * Defines modules that should be included to bundle. + * By default css-loader and `*.css` files allowed. + */ allow?: AllowlistItem | AllowlistItem[]; } +const NODE_EXTERNALS_DEFAULT_ALLOW: AllowlistItem[] = [ + // `css-loader` allowed by default to prevent errors about css-loader' runtime code was not found + /css-loader/, + + // css files allowed by default for using files from libraries like `overlay-scrollbars` or `@krutoo/showcase` + /\.css$/, +]; + /** - * Simple analogue of `webpack-node-externals`. - * Marks all files from node_modules as externals. + * Simple modern analogue of `webpack-node-externals`. + * Marks all files from `node_modules` as externals. * @param options Options. * @returns Externals function. */ export function nodeExternals({ - importType = 'commonjs', - - // css-loader allowed by default to prevent errors about css-loader' runtime code was not found - allow = [/css-loader/], + importType = 'module', + allow = NODE_EXTERNALS_DEFAULT_ALLOW, }: NodeExternalsOptions = {}): ExternalItem { const allowPredicates = allowToPredicates(allow);