Folder as entry in library mode for multiple independent js modules #8098
Replies: 4 comments 10 replies
-
This config saves my day of searching how to disable vite bundling all things into a There're some notes for the original solution.
import { defineConfig } from 'vite';
import path from 'path';
import glob from 'glob';
export default defineConfig({
build: {
outDir: 'dist',
emptyOutDir: true,
cssCodeSplit: true,
minify: false,
lib: {
entry: path.resolve(__dirname, 'src/generator/app/index.ts'),
formats: ['cjs'],
},
rollupOptions: {
external: ['yeoman-generator'],
input: glob.sync(path.resolve(__dirname, 'src/**/*.ts')),
output: {
preserveModules: true,
entryFileNames: (entry) => {
const { name, facadeModuleId } = entry;
const fileName = `${name}.js`;
if (!facadeModuleId) {
return fileName;
}
const relativeDir = path.relative(
path.resolve(__dirname, 'src'),
path.dirname(facadeModuleId),
);
return path.join(relativeDir, fileName);
},
},
},
},
}); I just copy-paste my config here in case of someone wants to build a |
Beta Was this translation helpful? Give feedback.
-
Is this code in vite.config.ts? I suppose so. But my build fails on this. As soon as I add line: |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot! You saved my way to develop my software. |
Beta Was this translation helpful? Give feedback.
-
here is a simple approach.. |
Beta Was this translation helpful? Give feedback.
-
I have the case that there is not one entry point for the library. There are several relatively independent js modules. In this library, there is also no bundling or minify what is expected behaviour for my case. In order to be able to specify all of them as
entry points, I have solved this as follows:
Idea: For a library that does not have a direct entry point but several individual js modules, it would be practical to be able to specify the lib entry as a folder. If it is a folder, it should then include all files, for example, with the extension *.js, *.html, *.css as entrypoints. The configuration remains the same, but a distinction is made between folder and file.
Beta Was this translation helpful? Give feedback.
All reactions