@@ -8,6 +8,11 @@ import { defineConfig } from 'vite';
88import dts from 'vite-plugin-dts' ;
99import { viteStaticCopy } from 'vite-plugin-static-copy' ;
1010import 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
1217export 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+ / ^ n o d e : .* / ,
62+ ...excludeAll ( dependencies ) ,
63+ ...excludeAll ( peerDependencies ) ,
64+ ] ,
5565 } ,
5666 } ,
5767 test : {
0 commit comments