Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow compiler option to be a path to the compiler module #1711

Merged
merged 2 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export { VueLoaderPlugin }

export interface VueLoaderOptions {
transformAssetUrls?: SFCTemplateCompileOptions['transformAssetUrls']
compiler?: TemplateCompiler
compiler?: TemplateCompiler | string
compilerOptions?: CompilerOptions
hotReload?: boolean
exposeFilename?: boolean
Expand Down
11 changes: 9 additions & 2 deletions src/templateLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import qs from 'querystring'
import loaderUtils from 'loader-utils'
import { VueLoaderOptions } from './'
import { formatError } from './formatError'
import { compileTemplate } from '@vue/compiler-sfc'
import { compileTemplate, TemplateCompiler } from '@vue/compiler-sfc'

// Loader that compiles raw template into JavaScript functions.
// This is injected by the global pitcher (../pitch) for template
Expand All @@ -23,11 +23,18 @@ const TemplateLoader: webpack.loader.Loader = function(source, inMap) {
const query = qs.parse(loaderContext.resourceQuery.slice(1))
const scopeId = query.scoped ? `data-v-${query.id}` : null

let compiler: TemplateCompiler | undefined
if (typeof options.compiler === 'string') {
compiler = require(options.compiler)
} else {
compiler = options.compiler
}

const compiled = compileTemplate({
source,
inMap,
filename: loaderContext.resourcePath,
compiler: options.compiler,
compiler,
compilerOptions: {
...options.compilerOptions,
scopeId
Expand Down