diff --git a/src/helpers.ts b/src/helpers.ts index 0e257c6..2214d8b 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -37,7 +37,7 @@ export const mergeSourceMaps = ( ) as RawSourceMap; }; -const NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/; +export const NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/; export async function applyRefresh( source: string, @@ -48,10 +48,6 @@ export async function applyRefresh( granular, }: { filename?: string; granular?: boolean } = {}, ) { - if (NODE_MODULES_REGEX.test(context.resourcePath)) { - return { code: source, map: sourceMap }; - } - const { transformRefreshAsync } = await import('@solidjs/compiler'); const result = await transformRefreshAsync(source, { filename: getTransformFilename(filename), diff --git a/src/index.ts b/src/index.ts index 7690a38..964bb61 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,6 +6,7 @@ import { applyRefresh, getTransformFilename, mergeSourceMaps, + NODE_MODULES_REGEX, normalizeSourceMap, } from './helpers.js'; import type { SolidCompiler, SolidPresetOptions } from './types.js'; @@ -27,6 +28,7 @@ export type SolidLoaderOptions = { const solidLoader: LoaderDefinition = async function ( source, sourceMap, + additionalData, ): Promise { const callback = this.async(); const options = this.getOptions(); @@ -37,7 +39,7 @@ const solidLoader: LoaderDefinition = async function ( options.scriptRegex && resourceFilename.search(options.scriptRegex) === -1 ) { - callback(null, source, sourceMap); + callback(null, source, sourceMap, additionalData); return; } @@ -52,7 +54,7 @@ const solidLoader: LoaderDefinition = async function ( solid.generate !== 'ssr'); try { - if (refresh) { + if (refresh && !NODE_MODULES_REGEX.test(sourceFilename)) { const result = await applyRefresh(source, sourceMap, this, { filename: resourceFilename, }); diff --git a/src/refresh.ts b/src/refresh.ts index 524373e..1fe0f40 100644 --- a/src/refresh.ts +++ b/src/refresh.ts @@ -1,14 +1,19 @@ import type { LoaderDefinition } from '@rspack/core'; -import { applyRefresh } from './helpers.js'; +import { applyRefresh, NODE_MODULES_REGEX } from './helpers.js'; export type SolidRefreshLoaderOptions = { granular?: boolean; }; const solidRefreshLoader: LoaderDefinition = - async function (source, sourceMap): Promise { + async function (source, sourceMap, additionalData): Promise { const callback = this.async(); + if (NODE_MODULES_REGEX.test(this.resourcePath)) { + callback(null, source, sourceMap, additionalData); + return; + } + try { const { granular } = this.getOptions(); const result = await applyRefresh(source, sourceMap, this, { granular });