Skip to content

Commit

Permalink
feat: scopeId support
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Dec 16, 2019
1 parent 4dad151 commit d9f932e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ const loader: webpack.loader.Loader = function(source) {
// TODO custom blocks
}

// attach scope Id for runtime use
if (hasScoped) {
code += `\nscript.__scopeId = "data-v-${id}"`
}

if (needsHotReload) {
code += `\nscript.__hmrId = "${id}"`
code += genHotReloadCode(id, templateRequest)
Expand Down
8 changes: 5 additions & 3 deletions src/templateLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ const TemplateLoader: webpack.loader.Loader = function(source, inMap) {
// const isServer = loaderContext.target === 'node'
// const isProduction = options.productionMode || loaderContext.minimize || process.env.NODE_ENV === 'production'
const query = qs.parse(this.resourceQuery.slice(1))
const scopedId = query.scoped ? `data-v-${query.id}` : null
scopedId // TODO this is for SSR
const scopeId = query.scoped ? `data-v-${query.id}` : null

const compiled = compileTemplate({
source,
filename: this.resourcePath,
compiler: options.compiler,
compilerOptions: options.compilerOptions,
compilerOptions: {
...options.compilerOptions,
scopeId
},
transformAssetUrls: options.transformAssetUrls || true
})

Expand Down

0 comments on commit d9f932e

Please sign in to comment.