-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.config.lib.js
93 lines (91 loc) · 2.87 KB
/
vite.config.lib.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import path from 'node:path'
import { defineConfig } from 'vite'
import {
cfg,
config,
pkg
} from './config'
import {
assetFileNames,
browserslistToEsbuild,
htmlcssjsLib,
newProcessEnv,
viteOptimizeOptions,
vitePreviewOptions,
viteServerOptions,
viteSharedOptions,
viteSsrOptions,
viteWorkerOptions
} from './lib'
const plugins = [htmlcssjsLib(config, pkg)]
if (
config.vitePlugins.lib &&
Array.isArray(config.vitePlugins.lib) &&
config.vitePlugins.lib.length
) {
plugins.push(...config.vitePlugins.lib)
}
export default ({ mode }) => {
process.env = newProcessEnv(mode, process.env, config)
return defineConfig({
appType: 'mpa',
base: './',
root: path.resolve(path.join(process.cwd(), config.src.root)),
publicDir: path.resolve(path.join(process.cwd(), config.src.public)),
envDir: process.cwd(),
envPrefix: cfg.envPrefix,
build: {
outDir: path.resolve(path.join(process.cwd(), config.out.lib.dest)),
assetsDir: cfg.assetsDir,
assetsInlineLimit: 0,
cssCodeSplit: false,
minify: mode === 'production' ? config.build.js.minify : false,
cssMinify: mode === 'production' ? config.build.css.minify : false,
sourcemap: false,
target: browserslistToEsbuild(),
cssTarget: browserslistToEsbuild(),
lib: {
entry: path.resolve(
process.cwd(), path.join(config.src.root, 'index.lib.js')
),
formats: config.build.js.libFormats,
name: config.build.js.name,
fileName: (format) => {
let hash = ''
if (true === config.build.js.hash) {
hash = '-[hash]'
}
if (format === 'es' || format === 'esm') {
return `js/${config.build.js.filename}${hash}.esm.js`
} else if (format === 'cjs') {
return `js/${config.build.js.filename}${hash}.cjs.js`
} else if (format === 'umd') {
return `js/${config.build.js.filename}${hash}.umd.js`
} else if (format === 'iife') {
return `js/${config.build.js.filename}${hash}.iife.js`
} else {
return `js/${config.build.js.filename}${hash}.${format}.js`
}
}
},
rollupOptions: {
external: config.build.js.external,
output: {
globals: config.build.js.globals,
assetFileNames: (assetInfo) => {
return assetFileNames(assetInfo, config, 'lib')
}
}
},
copyPublicDir: false,
emptyOutDir: config.out.lib.clean
},
plugins: plugins,
...viteSharedOptions(config.viteOptions.shared),
preview: vitePreviewOptions(config.viteOptions.preview),
server: viteServerOptions(config.viteOptions.server),
optimizeDeps: viteOptimizeOptions(config.viteOptions.optimize),
ssr: viteSsrOptions(config.viteOptions.ssr),
worker: viteWorkerOptions(config.viteOptions.worker)
})
}