-
Notifications
You must be signed in to change notification settings - Fork 5
/
createConfig.js
112 lines (104 loc) · 2.11 KB
/
createConfig.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
"use strict";
import path from 'path';
import json from 'rollup-plugin-json';
import commonjs from 'rollup-plugin-commonjs';
import resolve from 'rollup-plugin-node-resolve';
import babel from 'rollup-plugin-babel';
import typescript2 from 'rollup-plugin-typescript2';
import clear from 'rollup-plugin-clear';
import pkg from './package.json';
import { terser } from 'rollup-plugin-terser';
import fs from 'fs';
export const LIB_DIR = path.join(__dirname, './', 'src/lib')
export const ENTRY_MODULE_MAP = fs.readdirSync(path.resolve(LIB_DIR)).reduce((prev, name) => {
const stat = fs.statSync(`${LIB_DIR}/${name}`)
if (name.includes('.d.ts')) return prev
if (stat.isDirectory()) {
prev[`${name}/index`] = `${LIB_DIR}/${name}/index.ts`;
} else {
prev[`${name.replace('.ts', '')}`] = `${LIB_DIR}/${name}`;
}
return prev;
}, {});
const HEADER_TEXT = `
/**
* d-utils version: ${pkg.version}
* by ifmiss
*/
`
const plugins = [
clear({
targets: ['dist']
}),
json(),
typescript2(),
babel({
exclude: 'node_modules/**',
runtimeHelpers: true
}),
resolve({
mainFields: 'main',
modulesOnly: true
}),
commonjs({
include: 'node_modules/**',
sourceMap: true,
namedExports: {
react: [
'useState',
'useEffect',
'useMemo',
'useCallBack',
'useRef'
],
'react-router-dom': [
'useLocation'
]
}
}),
terser({
output: {
comments: true
}
})
]
export const moduleLists = [
{
input: {
index: 'src/lib/index.ts',
...ENTRY_MODULE_MAP
},
moduleType: 'es'
},
{
input: {
index: 'src/lib/index.ts',
},
moduleType: 'umd'
},
{
input: {
index: 'src/lib/index.ts',
...ENTRY_MODULE_MAP
},
moduleType: 'cjs'
}
]
const external = [
'sha1',
'weixin-js-sdk'
]
export const createConfig = (input, moduleType) => {
return {
input,
output: {
dir: path.resolve(__dirname, `dist/${moduleType}`),
format: moduleType,
banner: HEADER_TEXT,
exports: 'auto',
name: '[name].js'
},
external,
plugins
}
}