Skip to content

Commit

Permalink
feat: allow manually specifying whether server-rendering is targeted (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
haoqunjiang authored Nov 30, 2020
1 parent 388e030 commit 9bbb82b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export interface VueLoaderOptions {
hotReload?: boolean
exposeFilename?: boolean
appendExtension?: boolean

isServerBuild?: boolean
}

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

const isServer = target === 'node'
const isServer = options.isServerBuild ?? target === 'node'
const isProduction = mode === 'production'

const { descriptor, errors } = parse(source, {
Expand Down
2 changes: 1 addition & 1 deletion src/resolveScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function resolveScript(
}

const isProd = loaderContext.mode === 'production'
const isServer = loaderContext.target === 'node'
const isServer = options.isServerBuild ?? loaderContext.target === 'node'
const enableInline = canInlineTemplate(descriptor, isProd)

const cacheToUse = isServer ? serverCache : clientCache
Expand Down
2 changes: 1 addition & 1 deletion src/templateLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const TemplateLoader: webpack.loader.Loader = function (source, inMap) {
const options = (loaderUtils.getOptions(loaderContext) ||
{}) as VueLoaderOptions

const isServer = loaderContext.target === 'node'
const isServer = options.isServerBuild ?? loaderContext.target === 'node'
const isProd = loaderContext.mode === 'production'
const query = qs.parse(loaderContext.resourceQuery.slice(1))
const scopeId = query.id as string
Expand Down

0 comments on commit 9bbb82b

Please sign in to comment.