Skip to content

Commit 66309d4

Browse files
feat: removes __default-config__ comment blocks
1 parent ee2e8d7 commit 66309d4

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,17 @@ export const unpluginFactory: UnpluginFactory<Options | undefined> = (
160160
async transform(code, id) {
161161
// Replace all instances of `/* @__formkit_config__ */` in the code
162162
// with the resolved path to the formkit.config.{ts,js,mjs} file.
163-
if (configPath) {
163+
if (configPath && FORMKIT_CONFIG_RE.test(code)) {
164164
code = code.replace(FORMKIT_CONFIG_RE, `"${configPath}")`)
165+
if (options.defaultConfig === false) {
166+
// If the user has explicitly disabled the default config, we need
167+
// to remove the defaultConfig from the FormKitConfigLoader. We can
168+
// do this by cutting the /* @__default-config__ */ comment area.
169+
code = code.replace(
170+
/\/\* @__default-config__ \*\/(?:.|\n)+?\/\* @__default-config__ \*\//gi,
171+
'',
172+
)
173+
}
165174
}
166175
// Test if the given code is a likely candidate for FormKit usage.
167176
if (id.endsWith('.vue') && CONTAINS_FORMKIT_RE.test(code)) {

0 commit comments

Comments
 (0)