Skip to content

Commit 19c6a37

Browse files
committed
wip(vue2): add scopeId support for vue2
1 parent e46a1ab commit 19c6a37

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/createVue2SFCModule.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,21 @@ export async function createSFCModule(source : string, filename : string, option
7373

7474
const hasScoped = descriptor.styles.some(e => e.scoped);
7575

76+
// https://github.com/vuejs/vue-loader/blob/b53ae44e4b9958db290f5918248071e9d2445d38/lib/runtime/componentNormalizer.js#L36
77+
if (hasScoped) {
78+
Object.assign(component, {_scopeId: scopeId});
79+
}
80+
7681
const compileTemplateOptions : TemplateCompileOptions = descriptor.template ? {
7782
// hack, since sourceMap is not configurable an we want to get rid of source-map dependency. see genSourcemap
7883
source: descriptor.template.content,
7984
filename,
8085
compiler: vueTemplateCompiler as VueTemplateCompiler,
81-
compilerOptions: undefined,
86+
compilerOptions: {
87+
outputSourceRange: true,
88+
scopeId: hasScoped ? scopeId : null,
89+
comments: true
90+
} as any,
8291
preprocessLang: descriptor.template.lang,
8392
isProduction: isProd,
8493
prettify: false
@@ -139,7 +148,7 @@ export async function createSFCModule(source : string, filename : string, option
139148

140149
const template = sfc_compileTemplate(compileTemplateOptions);
141150
// "@vue/component-compiler-utils" does NOT assume any module system, and expose render in global scope.
142-
template.code += "\nmodule.exports = {render: render, staticRenderFns: staticRenderFns}"
151+
template.code += `\nexport { render, staticRenderFns }`
143152

144153
if ( template.errors.length ) {
145154

0 commit comments

Comments
 (0)