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
Feature request: support plugin inside of a vite project #1362
Comments
I think it'd be possible to get first class support with some effort, but I was able to hack what I need with the following vite config. I used the rollup plugin as a vite plugin, but wrote a custom filter to only run it on the client pass, and not the server pass. import license from 'rollup-plugin-license';
import {defineConfig} from 'vite';
const year = new Date().getFullYear();
export default defineConfig({
plugins: [
{
...license({
thirdParty: {
output: 'dist/client/assets/vendor.LICENSE.txt',
},
}),
apply: (config, configEnv) => {
// We only want to generate the file when not doing the ssr build
return !configEnv.ssrBuild;
},
enforce: 'post',
},
],
base: process.env.CDN_URL,
esbuild: {
legalComments: 'none',
banner: `/**
* Copyright me 2022-${year}
* See /assets/vendor.LICENSE.txt for 3rd party license information.
**/
`,
},
build: {
minify: true,
emptyOutDir: true,
sourcemap: false,
},
}); |
Hi @SlexAxton, I would be more than happy to add compatibility with vite. I've never used vite so far, but I thought rollup plugins were compatible, so I never looked at it. Could you explain what needs to be changed to support vite? |
Hi! Thanks for the response 🙏 I'm not totally sure what the differences are. I kinda thought the same as you. The specific thing that was happening though, was that vite was running the plugin twice, once for the 'client' and once for the 'server'. Because the output path was the same for both passes, the file would be written once, and then overwritten. For whatever reason the second pass didn't include the same amount of modules as the first pass. Presumably there's either some control to only run the build on one of the passes, or it's possible to pass in the build type (e.g. If you look at this list that they have https://vite-rollup-plugins.patak.dev/ they give various plugins that are compatible with vite and others that aren't. I wonder if there's a way to determine what makes one compatible vs another. There's also this section of the docs: https://vitejs.dev/guide/api-plugin.html#rollup-plugin-compatibility |
To me it works for generating But I was not able to see where would generated banner be. I tried config from the README. I do not care about generated banner though, so it is not a problem for me. |
I only noticed that during development, file is not made available somehow. Only for production build. This is probably fine and by design, it is just that it makes testing a bit clumsy. |
Apparently not all rollup plugins are compatible with vite, but I'd love to use this one with vite.
Inspired by #1361
Some docs here: https://vitejs.dev/guide/api-plugin.html#rollup-plugin-compatibility
Will try to look into it, but figured I'd log here in case anyone had any quick info. 🙏
The text was updated successfully, but these errors were encountered: