Skip to content

Commit

Permalink
feat: replace square brackets in bundle file name, close hannoeru#16
Browse files Browse the repository at this point in the history
  • Loading branch information
hannoeru committed Feb 27, 2021
1 parent ae2a9ea commit f2c1f39
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .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"]
}
10 changes: 10 additions & 0 deletions src/index.ts
Expand Up @@ -16,6 +16,7 @@ function resolveOptions(userOptions: UserOptions): ResolvedOptions {
routeBlockLang = 'json5',
exclude = [],
syncIndex = true,
replaceSquareBrackets = true,
} = userOptions

const root = process.cwd()
Expand Down Expand Up @@ -45,6 +46,7 @@ function resolveOptions(userOptions: UserOptions): ResolvedOptions {
importMode,
exclude,
syncIndex,
replaceSquareBrackets,
},
userOptions,
)
Expand Down Expand Up @@ -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}/`))
Expand Down
5 changes: 5 additions & 0 deletions src/types.ts
Expand Up @@ -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
*/
Expand Down

0 comments on commit f2c1f39

Please sign in to comment.