Skip to content

Commit 60f5674

Browse files
committed
chore: change Vite config for Qwik v2 🚀
1 parent 4880f99 commit 60f5674

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

‎packages/qwik-image/vite.config.ts‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import { defineConfig } from 'vite';
88
import dts from 'vite-plugin-dts';
99
import { viteStaticCopy } from 'vite-plugin-static-copy';
1010
import tsconfigPaths from 'vite-tsconfig-paths';
11+
import pkg from './package.json';
12+
13+
const { dependencies = {}, peerDependencies = {} } = pkg as any;
14+
const makeRegex = (dep: string) => new RegExp(`^${dep}(/.*)?$`);
15+
const excludeAll = (obj: string) => Object.keys(obj).map(makeRegex);
1116

1217
export default defineConfig({
1318
plugins: [
@@ -40,18 +45,23 @@ export default defineConfig({
4045
build: {
4146
target: 'es2020',
4247
lib: {
43-
entry: './src/index.ts',
44-
// Could also be a dictionary or array of multiple entry points.
45-
name: 'qwik-image',
46-
fileName: (format) => `index.qwik.${format === 'es' ? 'mjs' : 'cjs'}`,
47-
// fileName: 'index',
48-
// Change this to the formats you want to support.
49-
// Don't forgot to update your package.json as well.
50-
formats: ['es', 'cjs'],
48+
entry: './src/index',
49+
formats: ['es', 'cjs'] as const,
50+
// This adds .qwik so all files are processed by the optimizer
51+
fileName: (format, entryName) =>
52+
`${entryName}.qwik.${format === 'es' ? 'mjs' : 'cjs'}`,
5153
},
5254
rollupOptions: {
53-
// External packages that should not be bundled into your library.
54-
external: [],
55+
output: {
56+
preserveModules: true,
57+
preserveModulesRoot: 'src',
58+
},
59+
// externalize deps that shouldn't be bundled into the library
60+
external: [
61+
/^node:.*/,
62+
...excludeAll(dependencies),
63+
...excludeAll(peerDependencies),
64+
],
5565
},
5666
},
5767
test: {

0 commit comments

Comments
 (0)