-
Notifications
You must be signed in to change notification settings - Fork 14
/
rollup.config.js
86 lines (80 loc) · 2.31 KB
/
rollup.config.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
import path from 'path';
import babel from '@rollup/plugin-babel';
import nodeResolve from '@rollup/plugin-node-resolve';
import typescript from 'typescript';
import json from '@rollup/plugin-json';
import terser from '@rollup/plugin-terser';
import rollupTypescript from '@rollup/plugin-typescript';
import pkg from './package.json' assert { type: 'json' };
import copy from 'rollup-plugin-copy';
import { dirname } from 'path';
import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const extensions = ['.js', '.ts'];
const external = Object.keys(pkg.dependencies || '');
const globals = external.reduce((prev, current) => {
const newPrev = prev;
newPrev[current] = current;
return newPrev;
}, {});
const defaultConfig = {
input: pkg.main,
output: {
file: path.join(__dirname, pkg.lib),
format: 'es',
banner: '#!/usr/bin/env node',
globals
},
external,
plugins: [
rollupTypescript({
exclude: 'node_modules/**',
typescript,
tsconfig: './tsconfig.json'
}),
json(),
terser(),
nodeResolve({
extensions,
modulesOnly: true,
// 查找和打包node_modules中的第三方模块
customResolveOptions: {
moduleDirectories: ['src']
},
preferBuiltins: true
}),
babel({
exclude: 'node_modules/**',
extensions
}),
// 复制templates文件; 复制 .gitignore 文件;添加.npmignore文件:"!.gitignore\n.npmignore"
copy({
targets: [
'templates/farm/vue-lite',
'templates/farm/vue-next-lite',
'templates/farm/react-lite',
'templates/vite/vue-lite',
'templates/vite/vue-next-lite',
'templates/vite/react-lite',
'templates/webpack/vue-lite',
'templates/webpack/vue-next-lite',
'templates/webpack/react-lite',
]
.map((filePath) => [
{
src: [`${filePath}/*`, `${filePath}/.gitignore`, `!${filePath}/node_modules`],
dest: `bin/${filePath}`
},
{
src: `${filePath}/.gitignore`,
dest: `bin/${filePath}`,
rename: '.npmignore',
transform: () => Buffer.from('!.gitignore\n.npmignore', 'utf-8')
}
])
.flat(),
verbose: true
})
]
};
export default defaultConfig;