-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathrollup.config.js
136 lines (121 loc) · 3.43 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import batchPackages from '@lerna/batch-packages';
import filterPackages from '@lerna/filter-packages';
import { getPackages } from '@lerna/project';
import path from 'path';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import babel from 'rollup-plugin-babel';
import filesize from 'rollup-plugin-filesize';
import minimist from 'minimist';
import alias from 'rollup-plugin-alias';
/**
* Get a list of the non-private sorted packages with Lerna v3
* @see https://github.com/lerna/lerna/issues/1848
* @return {Promise<Package[]>} List of packages
*/
async function getSortedPackages() {
// Support --scope and --ignore globs
const { scope, ignore } = minimist(process.argv.slice(2));
// Standard Lerna plumbing getting packages
const packages = await getPackages(__dirname);
const filtered = filterPackages(
packages,
scope,
ignore,
false,
);
return batchPackages(filtered)
.reduce((arr, batch) => arr.concat(batch), []);
}
async function main() {
const plugins = [
alias({
resolve: ['.js', '.jsx'],
}),
resolve({
extensions: ['.js', '.jsx'],
}),
babel({
runtimeHelpers: true,
exclude: 'node_modules/**', // only transpile our source code
babelrc: false,
presets: [['@babel/preset-env', { modules: false }], '@babel/preset-react'],
plugins: [["lodash", { "id": ["recompose"] }]]
}),
commonjs({
namedExports: {
classnames: ['classNames'],
},
}),
filesize(),
];
if (process.env.NODE_ENV === 'production') {
// 添加压缩处理
}
const sourcemap = true;
const packages = await getSortedPackages();
const results = [];
packages.filter(pkg => pkg.name !== '@pile-ui/theme-default').forEach((pkg) => {
// Get settings from package JSON
const {
name, main, module, version, author,
} = pkg.toJSON();
const basePath = path.relative(__dirname, pkg.location);
const input = path.join(basePath, 'src/index.js');
// banner
const banner = `${'/*!\n'
+ ' * '}${name}.js v${version}\n`
+ ` * (c) 2018-${new Date().getFullYear()} ${author}\n`
+ ' * Released under the MIT License.\n'
+ ' */';
// Generate the externals to use, by default don't include dependencies
const baseExternal = ['react', 'react-dom'];
const external = [].concat(baseExternal, Object.keys(pkg.dependencies || []));
// cjs format output
const mainOutput = {
name,
file: path.join(basePath, main),
format: 'cjs',
sourcemap,
banner,
};
// ES format output
const moduleOutput = {
name,
file: path.join(basePath, module),
format: 'esm',
sourcemap,
banner,
};
results.push({
input,
output: [
mainOutput,
moduleOutput,
],
external,
plugins,
});
// bundle for browser
// 先关闭打包成umd,classnames模块打包有点问题
// issuse: https://github.com/rollup/rollup-plugin-commonjs/issues/256
//
// const rename = name.substr(6);
// results.push({
// input,
// external: baseExternal,
// output: {
// name,
// banner,
// globals: {},
// file: path.join(basePath, `/lib/${rename}.iife.js`),
// format: 'umd',
// sourcemap,
// },
// // treeshake: false,
// plugins,
// });
});
return results;
}
export default main();