1
- import { resolve } from ' path' ;
2
- import { readFileSync } from 'fs' ;
3
- import { rollup } from ' rollup' ;
4
- import { minify as minifyPlugin } from ' rollup-plugin-esbuild' ;
5
- import chalk from 'chalk' ;
1
+ import { resolve } from " path" ;
2
+ import { readFileSync } from "fs" ;
3
+ import { rollup } from " rollup" ;
4
+ import { minify as minifyPlugin } from " rollup-plugin-esbuild" ;
5
+ import picocolors from "picocolors" ;
6
6
import {
7
7
projPackage ,
8
8
target ,
@@ -13,9 +13,10 @@ import {
13
13
PKG_CAMEL_CASE_NAME ,
14
14
plugins ,
15
15
external ,
16
- } from '../helper' ;
16
+ globals ,
17
+ } from "../helper" ;
17
18
18
- const pkg = JSON . parse ( readFileSync ( projPackage , ' utf-8' ) ) ;
19
+ const pkg = JSON . parse ( readFileSync ( projPackage , " utf-8" ) ) ;
19
20
20
21
// 在 Rollup 中,banner 用于在打包生成的输出文件顶部添加一段文本。这段文本可以是版权声明、警告信息、版本号等任何你希望在文件开头显示的内容。
21
22
const banner = `/*! ${ PKG_NAME } v${ pkg . version } */\n` ;
@@ -30,48 +31,39 @@ const buildAll = async (minify?: boolean) => {
30
31
) ;
31
32
}
32
33
33
- console . log ( chalk . cyan ( `Starting build ${ minify ? ' compressed' : '' } full-bundle` ) ) ;
34
+ console . log ( picocolors . cyan ( `Starting build ${ minify ? " compressed " : "" } full-bundle` ) ) ;
34
35
35
36
// 配置详情地址:https://cn.rollupjs.org/configuration-options/
36
37
const bundle = await rollup ( {
37
- input : resolve ( tkRoot , ' index.ts' ) , // 打包入口文件
38
+ input : resolve ( tkRoot , "src/ index.ts" ) , // 打包入口文件
38
39
plugins,
39
40
external, // 指定外部依赖,Rollup 不会将这些依赖代码打包进去
40
41
treeshake : true , // 允许移除未使用的导出和代码
41
42
} ) ;
42
43
43
44
await writeBundles ( bundle , [
44
45
{
45
- format : ' umd' ,
46
- file : resolve ( tkOutput , `index${ minify ? ' .min' : '' } .js` ) , // 打包后的文件路径
47
- exports : ' named' ,
46
+ format : " umd" ,
47
+ file : resolve ( tkOutput , `index${ minify ? " .min" : "" } .js` ) , // 打包后的文件路径
48
+ exports : " named" ,
48
49
name : PKG_CAMEL_CASE_NAME , // 全局变量名称,通过这个变量名来访问打包后的入口文件,如浏览器端如果 window.${PKG_CAMEL_CASE_NAME} 访问
49
50
sourcemap : false ,
50
51
banner,
51
52
// 指定外部依赖: 当你将某些模块标记为 external 时,Rollup 不会将它们打包进最终的输出文件中。为了确保这些模块在运行时能够被正确引用,通过 globals 来指定这些模块对应的全局变量名称
52
- globals : {
53
- vue : 'Vue' ,
54
- 'node:path' : 'node:path' ,
55
- 'node:fs' : 'node:fs' ,
56
- fs : 'fs' ,
57
- chalk : 'Chalk' ,
58
- 'gray-matter' : 'GrayMatter' ,
59
- vitepress : 'VitePress' ,
60
- 'vitepress/theme' : 'VitePressTheme' ,
61
- } ,
53
+ globals,
62
54
} ,
63
55
{
64
- format : ' esm' ,
65
- file : resolve ( tkOutput , `index${ minify ? ' .min' : '' } .js` ) ,
56
+ format : " esm" ,
57
+ file : resolve ( tkOutput , `index${ minify ? " .min" : "" } .js` ) ,
66
58
sourcemap : false ,
67
59
} ,
68
60
] ) ;
69
61
70
62
const msg = minify
71
- ? ' Successfully build compressed full-bundle For umd and esm'
72
- : ' Successfully build full-bundle For umd and esm' ;
63
+ ? " Successfully build compressed full-bundle For umd and esm"
64
+ : " Successfully build full-bundle For umd and esm" ;
73
65
74
- console . log ( chalk . green ( msg ) ) ;
66
+ console . log ( picocolors . green ( msg ) ) ;
75
67
} ;
76
68
77
69
export default [ buildAll ( false ) , buildAll ( true ) ] ;
0 commit comments