Skip to content

Commit

Permalink
feat: allow compiler option to be a path to the compiler module (#1711
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sodatea committed Aug 11, 2020
1 parent cc6d6fa commit 064abd4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
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

0 comments on commit 064abd4

Please sign in to comment.