Skip to content

Commit d9f932e

Browse files
committed
feat: scopeId support
1 parent 4dad151 commit d9f932e

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ const loader: webpack.loader.Loader = function(source) {
160160
// TODO custom blocks
161161
}
162162

163+
// attach scope Id for runtime use
164+
if (hasScoped) {
165+
code += `\nscript.__scopeId = "data-v-${id}"`
166+
}
167+
163168
if (needsHotReload) {
164169
code += `\nscript.__hmrId = "${id}"`
165170
code += genHotReloadCode(id, templateRequest)

src/templateLoader.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ const TemplateLoader: webpack.loader.Loader = function(source, inMap) {
2222
// const isServer = loaderContext.target === 'node'
2323
// const isProduction = options.productionMode || loaderContext.minimize || process.env.NODE_ENV === 'production'
2424
const query = qs.parse(this.resourceQuery.slice(1))
25-
const scopedId = query.scoped ? `data-v-${query.id}` : null
26-
scopedId // TODO this is for SSR
25+
const scopeId = query.scoped ? `data-v-${query.id}` : null
2726

2827
const compiled = compileTemplate({
2928
source,
3029
filename: this.resourcePath,
3130
compiler: options.compiler,
32-
compilerOptions: options.compilerOptions,
31+
compilerOptions: {
32+
...options.compilerOptions,
33+
scopeId
34+
},
3335
transformAssetUrls: options.transformAssetUrls || true
3436
})
3537

0 commit comments

Comments
 (0)