Skip to content

Commit f6c7049

Browse files
committed
feat: support passing in compiler-sfc options
1 parent f1d3e10 commit f6c7049

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/Repl.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import SplitPane from './SplitPane.vue'
33
import Editor from './editor/Editor.vue'
44
import Output from './output/Output.vue'
5-
import { ReplStore } from './store'
5+
import { ReplStore, SFCOptions } from './store'
66
import { provide, toRef } from 'vue'
77
88
interface Props {
@@ -11,6 +11,7 @@ interface Props {
1111
showCompileOutput?: boolean
1212
showImportMap?: boolean
1313
clearConsole?: boolean
14+
sfcOptions?: SFCOptions
1415
}
1516
1617
const props = withDefaults(defineProps<Props>(), {
@@ -21,6 +22,8 @@ const props = withDefaults(defineProps<Props>(), {
2122
clearConsole: true
2223
})
2324
25+
props.store.options = props.sfcOptions
26+
2427
provide('store', props.store)
2528
provide('autoresize', props.autoResize)
2629
provide('import-map', toRef(props, 'showImportMap'))

src/store.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import { version, reactive, watchEffect } from 'vue'
22
import * as defaultCompiler from 'vue/compiler-sfc'
33
import { compileFile } from './transform'
44
import { utoa, atou } from './utils'
5+
import {
6+
SFCScriptCompileOptions,
7+
SFCAsyncStyleCompileOptions,
8+
SFCTemplateCompileOptions
9+
} from 'vue/compiler-sfc'
510

611
const defaultMainFile = 'App.vue'
712

@@ -41,9 +46,16 @@ export interface StoreState {
4146
vueRuntimeURL: string
4247
}
4348

49+
export interface SFCOptions {
50+
script?: SFCScriptCompileOptions
51+
style?: SFCAsyncStyleCompileOptions
52+
template?: SFCTemplateCompileOptions
53+
}
54+
4455
export class ReplStore {
4556
state: StoreState
4657
compiler = defaultCompiler
58+
options?: SFCOptions
4759
defaultVueRuntimeURL: string
4860
pendingCompiler: Promise<any> | null = null
4961

src/transform.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ export async function compileFile(
178178
}
179179

180180
const styleResult = await store.compiler.compileStyleAsync({
181+
...store.options?.style,
181182
source: style.content,
182183
filename,
183184
id,
@@ -218,13 +219,15 @@ async function doCompileScript(
218219
? ['typescript']
219220
: undefined
220221
const compiledScript = store.compiler.compileScript(descriptor, {
221-
id,
222-
refTransform: true,
223222
inlineTemplate: true,
223+
...store.options?.script,
224+
id,
224225
templateOptions: {
226+
...store.options?.template,
225227
ssr,
226228
ssrCssVars: descriptor.cssVars,
227229
compilerOptions: {
230+
...store.options?.template?.compilerOptions,
228231
expressionPlugins
229232
}
230233
}
@@ -268,6 +271,7 @@ function doCompileTemplate(
268271
isTS: boolean
269272
) {
270273
const templateResult = store.compiler.compileTemplate({
274+
...store.options?.template,
271275
source: descriptor.template!.content,
272276
filename: descriptor.filename,
273277
id,
@@ -277,6 +281,7 @@ function doCompileTemplate(
277281
ssrCssVars: descriptor.cssVars,
278282
isProd: false,
279283
compilerOptions: {
284+
...store.options?.template?.compilerOptions,
280285
bindingMetadata,
281286
expressionPlugins: isTS ? ['typescript'] : undefined
282287
}

0 commit comments

Comments
 (0)