diff --git a/.eslintrc.json b/.eslintrc.json index b7af0aa8..af1f4271 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,7 +1,8 @@ { "extends": "@antfu/eslint-config", "rules": { - "@typescript-eslint/no-unused-vars": "off" + "@typescript-eslint/no-unused-vars": "off", + "no-restricted-syntax": "off" }, "ignorePatterns": ["dist"] } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 885d94d9..8bf000bb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,6 +16,7 @@ function resolveOptions(userOptions: UserOptions): ResolvedOptions { routeBlockLang = 'json5', exclude = [], syncIndex = true, + replaceSquareBrackets = true, } = userOptions const root = process.cwd() @@ -45,6 +46,7 @@ function resolveOptions(userOptions: UserOptions): ResolvedOptions { importMode, exclude, syncIndex, + replaceSquareBrackets, }, userOptions, ) @@ -115,6 +117,14 @@ function routePlugin(userOptions: UserOptions = {}): Plugin { map: null, } }, + generateBundle(_options, bundle) { + if (options.replaceSquareBrackets) { + for (const name in bundle) { + const chunk = bundle[name] + chunk.fileName = chunk.fileName.replace(/(\[|\])/g, '_') + } + } + }, async handleHotUpdate({ file, server, read }) { const extensionsRE = new RegExp(`\\.(${options.extensions.join('|')})$`) const matchedPath = (pagesDirPaths).find(p => file.startsWith(`${p}/`)) diff --git a/src/types.ts b/src/types.ts index 1b80dcea..57e0b3a5 100644 --- a/src/types.ts +++ b/src/types.ts @@ -56,6 +56,11 @@ interface Options { * @default 'json5' */ routeBlockLang: 'json5' | 'json' | 'yaml' + /** + * Replace '[]' to '_' in bundle chunk filename + * @default true + */ + replaceSquareBrackets: boolean /** * Extend route records */