@purekit/rollup-config 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/index.mjs +82 -69
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/index.mjs
CHANGED
|
@@ -1,69 +1,82 @@
|
|
|
1
|
-
import typescript from
|
|
2
|
-
import resolve from
|
|
3
|
-
import commonjs from
|
|
4
|
-
import terser from '@rollup/plugin-terser';
|
|
5
|
-
import dts from
|
|
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
|
-
}
|
|
1
|
+
import typescript from '@rollup/plugin-typescript';
|
|
2
|
+
import resolve from '@rollup/plugin-node-resolve';
|
|
3
|
+
import commonjs from '@rollup/plugin-commonjs';
|
|
4
|
+
import terser from '@rollup/plugin-terser';
|
|
5
|
+
import dts from 'rollup-plugin-dts';
|
|
6
|
+
import alias from '@rollup/plugin-alias';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 创建 Rollup 配置
|
|
11
|
+
* @param {Object} options 自定义选项
|
|
12
|
+
* @param {string} options.input 入口文件,默认为 "src/index.ts"
|
|
13
|
+
*/
|
|
14
|
+
export function createConfig(options = {}) {
|
|
15
|
+
const input = options.input || 'src/index.ts';
|
|
16
|
+
const dist = 'dist';
|
|
17
|
+
|
|
18
|
+
const projectRoot = process.cwd();
|
|
19
|
+
|
|
20
|
+
const defaultOutput = [
|
|
21
|
+
{
|
|
22
|
+
file: `${dist}/index.js`,
|
|
23
|
+
format: 'cjs',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
file: `${dist}/index.mjs`,
|
|
27
|
+
format: 'es',
|
|
28
|
+
},
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
let finalOutput = options.output || defaultOutput;
|
|
32
|
+
|
|
33
|
+
if (!Array.isArray(finalOutput)) {
|
|
34
|
+
finalOutput = [finalOutput];
|
|
35
|
+
}
|
|
36
|
+
finalOutput = finalOutput.map((item) => ({
|
|
37
|
+
...item,
|
|
38
|
+
sourcemap: false,
|
|
39
|
+
}));
|
|
40
|
+
|
|
41
|
+
const isMinify = /(build|publish)/.test(process.env.npm_lifecycle_event || '');
|
|
42
|
+
|
|
43
|
+
const jsConfig = {
|
|
44
|
+
input,
|
|
45
|
+
output: finalOutput,
|
|
46
|
+
external: (id) => /node_modules/.test(id),
|
|
47
|
+
plugins: [
|
|
48
|
+
alias({
|
|
49
|
+
entries: [
|
|
50
|
+
{
|
|
51
|
+
find: '@',
|
|
52
|
+
replacement: path.resolve(projectRoot, 'src'),
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
}),
|
|
56
|
+
resolve(),
|
|
57
|
+
commonjs(),
|
|
58
|
+
typescript({
|
|
59
|
+
tsconfig: './tsconfig.json',
|
|
60
|
+
declaration: false,
|
|
61
|
+
}),
|
|
62
|
+
isMinify
|
|
63
|
+
? terser({
|
|
64
|
+
format: { comments: false },
|
|
65
|
+
compress: {
|
|
66
|
+
drop_console: false,
|
|
67
|
+
drop_debugger: true,
|
|
68
|
+
pure_funcs: ['console.log', 'console.info', 'console.debug'],
|
|
69
|
+
},
|
|
70
|
+
})
|
|
71
|
+
: null,
|
|
72
|
+
],
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const dtsConfig = {
|
|
76
|
+
input,
|
|
77
|
+
output: [{ file: `${dist}/index.d.ts`, format: 'es' }],
|
|
78
|
+
plugins: [dts()],
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return [jsConfig, dtsConfig];
|
|
82
|
+
}
|