-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
97 lines (93 loc) · 2.24 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
87
88
89
90
91
92
93
94
95
96
97
const commonjs = require('@rollup/plugin-commonjs')
const typescript = require('rollup-plugin-typescript2')
const json = require('@rollup/plugin-json')
const path = require('path')
const { babel } = require('@rollup/plugin-babel')
const { nodeResolve } = require('@rollup/plugin-node-resolve')
const postcss = require('rollup-plugin-postcss')
const less = require('less')
const packageJson = require('./package.json')
const babelOptions = {
presets: ['@babel/preset-env'],
extensions: ['.js', '.jsx', '.ts', '.tsx', '.scss'],
exclude: '**/node_modules/**',
}
const processLess = function (context, payload) {
return new Promise((resolve, reject) => {
less.render(
{
file: context,
},
function (err, result) {
if (!err) {
resolve(result)
} else {
reject(err)
}
}
)
less.render(context, {}).then(
function (output) {
// output.css = string of css
// output.map = string of sourcemap
// output.imports = array of string filenames of the imports referenced
if (output && output.css) {
resolve(output.css)
} else {
reject({})
}
},
function (err) {
reject(err)
}
)
})
}
module.exports = [
{
input: path.resolve(__dirname, 'src/index.tsx'),
output: [
{ file: path.resolve(__dirname, packageJson.module), format: 'esm' },
],
external: ['react', 'react-dom'],
plugins: [
postcss({
extract: false,
modules: true,
process: processLess,
}),
// nodeResolve(),
commonjs(),
typescript({
check: false, // 不检查ts报错
}),
json(),
babel(babelOptions),
],
},
{
input: path.resolve(__dirname, 'src/index.tsx'),
output: [
{ file: path.resolve(__dirname, packageJson.main), format: 'umd', name: packageJson.name },
],
external: [
'react',
'react-dom',
'antd'
],
plugins: [
postcss({
extract: false,
modules: true,
process: processLess,
}),
// nodeResolve(),
commonjs(),
typescript({
check: false, // 不检查ts报错
}),
json(),
babel(babelOptions),
],
}
]