Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to specify an output prefix and load app id from appinfo #207

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat(app-config): Allow to specify assets prefix
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Jun 20, 2024
commit eb4410c9895b79c955c26ee038b540bc95c5a0a0
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