-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat(qwikVite): add possibility to define multiple outputs #6452
Conversation
👷 Deploy request for qwik-insights pending review.Visit the deploys page to approve it
|
amazing 🙏 |
Thanks for the approve @PatrickJS, I've added one small improvement in case the provided output array is empty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small changes, looks good overall!
a311c97
to
97891b3
Compare
Run & review this pull request in StackBlitz Codeflow. commit: @builder.io/qwik
@builder.io/qwik-city
eslint-plugin-qwik
create-qwik
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
) * add possibility to define multiple outputs in vite * more explicit assertions in tests * simplify code * small improvement to make sure at least one output is present in every case * change variable name so the history is easier to follow * fix(vite.unit.ts): grab plugin --------- Co-authored-by: PatrickJS <github@gdi2290.com>
Hey @KingSora @PatrickJS @wmertens after the merge of this PR, the vite config is overwrited.
import { defineConfig } from "vite";
import pkg from "./package.json";
import { qwikVite } from "@builder.io/qwik/optimizer";
import tsconfigPaths from "vite-tsconfig-paths";
const { dependencies = {}, peerDependencies = {} } = pkg as any;
const makeRegex = (dep) => new RegExp(`^${dep}(/.*)?$`);
const excludeAll = (obj) => Object.keys(obj).map(makeRegex);
export default defineConfig(({ command }) => {
return {
plugins: [qwikVite(), tsconfigPaths()],
build: {
target: "es2020",
lib: {
entry: "src/lib/index.ts",
formats: ["es", "cjs"],
fileName: (format, entry) => {
console.log({ format, entry });
const ext = format === "es" ? "mjs" : "cjs";
const name = entry;
return `${name}.qwik.${ext}`;
},
},
rollupOptions: {
// externalize deps that shouldn't be bundled into the library
external: [
/^node:.*/,
...excludeAll(dependencies),
...excludeAll(peerDependencies),
],
},
},
};
}); as you can see, I do not have a rollup custom configuration, and also, I got setup the
Note I tried with |
Ok we have to revert this, I also encountered it without realizing what it was. @KingSora can you explain why you needed this and why you can't use the vite lib option? |
@wmertens All of the behavior changes are happening because of my assumption of this: rollupOptions: {
output: [
{
/** ...my output options... */
}
]
} being equivalent to this: rollupOptions: {
output: {
/** ...my output options... */
}
} I can submit a PR if you are interested to fix this behavior with the suggestion I did in #6643:
This should restore the original behavior for all users but keep the possibility to define multiple outputs if you need them.
Yes, for a library I'm working on I needed multiple build targets an a way that vites |
@KingSora ok, I propose you add a helper function in plugin.ts that can extract the first input from any form of input, and that you normalize the inputs without changing their form. So then the image plugin stuff etc will still break for multi output but at least not in normal use and hopefully that gets fixed sometime. |
Overview
What is it?
Description
I'm using
qwikVite
to bundle my library. Because my setup requires multiple output files per format, I've tried to use therollupOptions.output
field to achieve this:This did work but always created one additional output file which I didn't specify in the config. That happens because the
qwikVite
plugin is not handling output arrays correctly.Use cases and why
The possibility to achieve multiple outputs for library authors.
Checklist: