Skip to content

Commit a2262ce

Browse files
committed
fix: do not throw when there's no script block in the SFC
1 parent f19f2b3 commit a2262ce

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/templateLoader.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ const TemplateLoader: webpack.loader.Loader = function(source, inMap) {
3838
compilerOptions: {
3939
...options.compilerOptions,
4040
scopeId,
41-
bindingMetadata: JSON.parse(query.bindings as string)
41+
bindingMetadata:
42+
typeof query.bindings === 'string' ? JSON.parse(query.bindings) : {}
4243
},
4344
transformAssetUrls: options.transformAssetUrls || true
4445
})

test/core.spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ test('basic', async () => {
77
test('script setup', async () => {
88
await bundle({ entry: 'ScriptSetup.vue' })
99
})
10+
11+
test('without script block', async () => {
12+
await bundle({ entry: 'no-script.vue' })
13+
})

test/fixtures/no-script.vue

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<template>
2+
<h2 class="red">hello</h2>
3+
</template>
4+
5+
<style>
6+
h2 {
7+
color: #f00;
8+
}
9+
</style>

0 commit comments

Comments
 (0)