Skip to content

Commit

Permalink
fix: 🐛 css asset path
Browse files Browse the repository at this point in the history
  • Loading branch information
woldtwerk committed Nov 22, 2023
1 parent e7fdc5c commit 9e5b401
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions packages/vite-plugin-drupal/src/plugins/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ export default (ctx: Context): Plugin => {
return {
name: 'vite-plugin-uebertool-config',
async config(config) {
const input = await fg([
'(js|css|templates)/**/*.(js|jsx|css|ts|tsx)',
], {
onlyFiles: true,
ignore: [
'**/*.stories.*',
'**/*.ce.*',
'**/_*',
'**/*.d.ts',
'./js/composables/**',
'./js/stores/**',
'./js/utils/**',
],
})

return mergeConfig(config, {
...(!(await postCssConfig()) && {
css: {
Expand Down Expand Up @@ -53,24 +68,14 @@ export default (ctx: Context): Plugin => {
target: 'esnext',
manifest: true,
rollupOptions: {
input: await fg([
'(js|css|templates)/**/*.(js|jsx|css|ts|tsx)',
], {
onlyFiles: true,
ignore: [
'**/*.stories.*',
'**/*.ce.*',
'**/_*',
'**/*.d.ts',
'./js/composables/**',
'./js/stores/**',
'./js/utils/**',
],
}),
input,
output: {
manualChunks: {
'vue.runtime.esm-browser.prod': ['vue'],
// 'alpine.runtime': ['alpinejs'],
manualChunks: (id: string) => {
if (id.match(/@vue\+runtime/))
return 'vue.runtime.esm-browser.prod'

if (id.match(/alpinejs@/))
return 'alpine.runtime'
},
assetFileNames: (assetInfo: any) => {
const base = basename(assetInfo.name)
Expand All @@ -79,9 +84,13 @@ export default (ctx: Context): Plugin => {
if (assetMap.has(base))
return assetMap.get(base)

const fullPath = input.find(file => file.endsWith(base))
if (fullPath)
dir = dirname(fullPath)

dir = dir.startsWith('.') ? '' : `${dir}/`
assetMap.set(base, `${dir}[name].[hash].[ext]`)

assetMap.set(base, `${dir}[name].[hash].[ext]`)
return '[name].[hash].[ext]'
},
entryFileNames: (assetInfo: any) => {
Expand Down

0 comments on commit 9e5b401

Please sign in to comment.