-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrollup.config.js
More file actions
45 lines (39 loc) · 1.13 KB
/
rollup.config.js
File metadata and controls
45 lines (39 loc) · 1.13 KB
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
// rollup.config.js
/**
* @file rollup.config.js
* @description Transfer ts into es6
*/
import resolve from 'rollup-plugin-node-resolve'
import ts from 'rollup-plugin-typescript2'
import typescript from 'typescript'
import glob from 'glob'
import tsImportPluginFactory from 'ts-import-plugin'
let options = []
const transformer = () => ({
before: [
tsImportPluginFactory({
libraryDirectory: 'lib',
libraryName: 'antd',
style: 'css'
})
]
})
glob.sync('src/components/**/*.tsx').forEach(path => {
/* path example: src/components/Clock/index.tsx */
/* convert input path into output path */
const reg = new RegExp(/style/)
const isStyle = reg.test(path.split('/')[3]) || reg.test(path.split('/')[2])
if (isStyle) return
const outputPath = path
.replace(/^src/, 'sep')
.replace(/components/, 'es')
.replace(/.tsx$/, '.js')
options.push({
input: path,
output: { file: outputPath, format: 'esm' },
treeshake: true,
plugins: [resolve(), ts({ typescript, transformers: [transformer] })],
external: id => /react|antd|classnames|prop-types/.test(id)
})
})
export default options