Is possible to preserve assets folder structure? #2447
Replies: 6 comments 4 replies
-
I really really need this option, especially when I want to keep the image/css directory structure. |
Beta Was this translation helpful? Give feedback.
-
It will be great to have this in library mode |
Beta Was this translation helpful? Give feedback.
-
I'm also new to vite import {defineConfig} from 'vite';
import laravel from 'laravel-vite-plugin';
import {viteStaticCopy} from 'vite-plugin-static-copy'
import {glob} from "glob";
export default defineConfig({
build: {
manifest: true,
rtl: true,
outDir: 'public/assets/',
cssCodeSplit: true,
rollupOptions: {
output: {
assetFileNames: (asset) => {
switch (asset.name.split('.').pop()) {
case 'css':
return 'css/' + `[name]` + '.min.css';
case 'png':
case 'jpg':
case 'ico':
case 'svg':
return 'images/' + `[name]` + `[extname]`;
//TODO how to handle svg fonts? (they can be both font or image?)
case 'ttf':
case 'otf':
case 'woff':
case 'woff2':
return 'fonts/' + `[name]` + `[extname]`;
default:
return 'other/' + `[name]` + `[extname]`;
}
},
entryFileNames: 'js/' + `[name]` + `.min.js`,
},
},
},
plugins: [
laravel(
{
input: [
'resources/scss/bootstrap.scss',
'resources/scss/icons.scss',
'resources/scss/app.scss',
'resources/scss/custom.scss',
...glob.sync("resources/css/*.css"),
'resources/js/app.js',
'resources/js/api.js',
'resources/js/ConstantMapper.js',
'resources/js/helpers.js',
'resources/js/index.js',
'resources/js/reload.js',
],
refresh: true
}
),
viteStaticCopy({
targets: [
{
src: 'resources/static/css',
dest: ''
},
{
src: 'resources/static/images',
dest: ''
},
{
src: 'resources/static/js',
dest: ''
},
{
src: 'resources/static/json',
dest: ''
},
]
}),
],
}); |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
I'm used to achieving this with Rollup using the export default {
input: ['src/module.js', `src/another/module.js`],
output: [
{
format: 'es',
dir: 'dist',
preserveModules: true,
preserveModulesRoot: 'src',
},
],
} So I would assume you can do it with Vite by simply setting that option in |
Beta Was this translation helpful? Give feedback.
-
I created a PR to add an option to vite for this. #17626 |
Beta Was this translation helpful? Give feedback.
-
I noticed Vite generates a flat assets structure when generating the bundle.
vite/packages/vite/src/node/plugins/asset.ts
Lines 223 to 228 in ad50060
This is ideal when generating static sites, because where assets are stored are not "quite" important.
But in a context that Vite is a complementary tool, it would be good to have an option to preserve such directory structure. Specially for large projects.
For example:
I would like my fonts to be stored inside the
assets/fonts/
folder.src/fonts/font.woff2
dist/assets/fonts/font.[hash].woff2
But Instead I get:
src/fonts/font.woff2
dist/assets/font.[hash].woff2
I noticed this behavior for CSS
url()
assets and for<img>
tags.Here is something to illustrate:
I don't know the impact to have such option available, I'm merely raising a question to see if other folks can share the same opinion.
Beta Was this translation helpful? Give feedback.
All reactions