Skip to content

Commit

Permalink
feat(app-config): Allow to specify assets prefix
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Jun 20, 2024
1 parent b6c6c9c commit eb4410c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/appConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ export interface AppOptions extends Omit<BaseOptions, 'inlineCSS'> {
*/
appName?: string

/**
* Prefix to use for assets and chunks
* @default '{appName}-'
*/
assetsPrefix?: string

/**
* Inject all styles inside the javascript bundle instead of emitting a .css file
* @default false
Expand Down Expand Up @@ -86,6 +92,8 @@ export const createAppConfig = (entries: { [entryAlias: string]: string }, optio
config: async (env) => {
console.info(`Building ${options.appName} for ${env.mode}`)

const assetsPrefix = (options.assetsPrefix ?? `${options.appName}-`).replace(/[/\\]/, '-')

// This config is used to extend or override our base config
// Make sure we get a user config and not a promise or a user config function
const userConfig = await Promise.resolve(typeof options.config === 'function' ? options.config(env) : options.config)
Expand Down Expand Up @@ -162,17 +170,17 @@ export const createAppConfig = (entries: { [entryAlias: string]: string }, optio
if (/png|jpe?g|svg|gif|tiff|bmp|ico/i.test(extType)) {
return 'img/[name][extname]'
} else if (/css/i.test(extType)) {
return `css/${sanitizeAppName(options.appName)}-[name].css`
return `css/${assetsPrefix}[name].css`
} else if (/woff2?|ttf|otf/i.test(extType)) {
return 'css/fonts/[name][extname]'
}
return 'dist/[name]-[hash][extname]'
},
entryFileNames: () => {
return `js/${sanitizeAppName(options.appName)}-[name].mjs`
return `js/${assetsPrefix}[name].mjs`
},
chunkFileNames: () => {
return 'js/[name]-[hash].mjs'
return 'js/[name].chunk.mjs'
},
manualChunks: {
...(options?.coreJS ? { polyfill: ['core-js'] } : {}),
Expand Down

0 comments on commit eb4410c

Please sign in to comment.