Skip to content

Commit 9bbb82b

Browse files
authored
feat: allow manually specifying whether server-rendering is targeted (#1764)
This option provides a solution for #1734 When testing with mocha + mochapack, even though the target environment is `node`, the compiled component is expected to be run with `jsdom` rather than with a Node.js server, so it should still be a client bundle.
1 parent 388e030 commit 9bbb82b

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

src/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ export interface VueLoaderOptions {
4343
hotReload?: boolean
4444
exposeFilename?: boolean
4545
appendExtension?: boolean
46+
47+
isServerBuild?: boolean
4648
}
4749

4850
let errorEmitted = false
@@ -85,7 +87,7 @@ export default function loader(
8587
const options = (loaderUtils.getOptions(loaderContext) ||
8688
{}) as VueLoaderOptions
8789

88-
const isServer = target === 'node'
90+
const isServer = options.isServerBuild ?? target === 'node'
8991
const isProduction = mode === 'production'
9092

9193
const { descriptor, errors } = parse(source, {

src/resolveScript.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function resolveScript(
3333
}
3434

3535
const isProd = loaderContext.mode === 'production'
36-
const isServer = loaderContext.target === 'node'
36+
const isServer = options.isServerBuild ?? loaderContext.target === 'node'
3737
const enableInline = canInlineTemplate(descriptor, isProd)
3838

3939
const cacheToUse = isServer ? serverCache : clientCache

src/templateLoader.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const TemplateLoader: webpack.loader.Loader = function (source, inMap) {
2020
const options = (loaderUtils.getOptions(loaderContext) ||
2121
{}) as VueLoaderOptions
2222

23-
const isServer = loaderContext.target === 'node'
23+
const isServer = options.isServerBuild ?? loaderContext.target === 'node'
2424
const isProd = loaderContext.mode === 'production'
2525
const query = qs.parse(loaderContext.resourceQuery.slice(1))
2626
const scopeId = query.id as string

0 commit comments

Comments
 (0)