-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
84 lines (79 loc) · 2.45 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
import typescript from 'rollup-plugin-typescript2'
import commonjs from 'rollup-plugin-commonjs'
import resolve from 'rollup-plugin-node-resolve'
import postcss from 'rollup-plugin-postcss'
import sass from 'node-sass'
import fs from 'fs'
import path from 'path'
const componentDir = 'src/components';
const cModuleNames = fs.readdirSync(path.resolve(componentDir));
const cModuleMap = cModuleNames.filter(name =>
!/(.ts|.tsx)$/.test(name)
).reduce((prev, name) => {
prev[name] = `${componentDir}/${name}/index.tsx`;
return prev;
}, {});
let override = { compilerOptions: { declaration: true, allowJs: false, isolatedModules: false } };
const rollupConfig = {
experimentalCodeSplitting: true,
external: id => ['react'].some(e => id.indexOf(e) === 0),
plugins: [
typescript({
// tsconfigDefaults: defaults,
tsconfig: "tsconfig.json",
tsconfigOverride: override
}),
resolve(),
commonjs({
extensions: ['.js', '.ts', '.jsx', '.tsx'],
include: [
'node_modules/**'
],
exclude: [
'node_modules/process-es6/**'
],
namedExports: {
'node_modules/react/index.js': ['useState', 'useRef', 'useCallback', 'useMemo', 'useEffect', 'memo'],
'node_modules/react-dom/index.js': ['render']
}
}),
postcss({
// extract: true,
minimize: 'production',
extensions: ['css', 'scss'],
process: (context) => {
console.log(context)
return new Promise((resolve, reject) => {
sass.render({
file: context
}, function (err, result) {
if (!err) {
resolve(result);
} else {
reject(err)
}
});
})
},
}),
]
}
export default [{
input: { index: "src/components/index.ts" },
output: {
dir: 'es',
format: 'es',
entryFileNames: 'components/index.js', // 输出文件名
exports: 'named'
},
...rollupConfig
}, {
input: cModuleMap,
output: {
dir: 'es',
format: 'es',
entryFileNames: 'components/[name]/index.js', // 输出文件名
exports: 'named'
},
...rollupConfig
}]