@@ -8,6 +8,11 @@ import { defineConfig } from 'vite';
8
8
import dts from 'vite-plugin-dts' ;
9
9
import { viteStaticCopy } from 'vite-plugin-static-copy' ;
10
10
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 ) ;
11
16
12
17
export default defineConfig ( {
13
18
plugins : [
@@ -40,18 +45,23 @@ export default defineConfig({
40
45
build : {
41
46
target : 'es2020' ,
42
47
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' } ` ,
51
53
} ,
52
54
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
+ ] ,
55
65
} ,
56
66
} ,
57
67
test : {
0 commit comments