-
Notifications
You must be signed in to change notification settings - Fork 17
/
rollup.config.js
141 lines (136 loc) · 3.06 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
137
138
139
140
141
import babel from "@rollup/plugin-babel";
import commonjs from "@rollup/plugin-commonjs";
import resolve from "@rollup/plugin-node-resolve";
import url from "@rollup/plugin-url";
import external from "rollup-plugin-peer-deps-external";
import postcss from "rollup-plugin-postcss";
import svgr from "@svgr/rollup";
import image from "@rollup/plugin-image";
import { terser } from "rollup-plugin-terser";
const fs = require("fs");
const path = require("path");
const production = !process.env.ROLLUP_WATCH;
if (production) {
//删除dist文件夹
console.log("删除dist文件夹中...");
deleteFolder(path.resolve(__dirname, `dist`));
console.log("删除dist文件夹完毕!开始打包...");
}
export default {
input: "src/index.js",
output: [
{
dir: "dist/cjs",
format: "cjs",
sourcemap: false,
},
{
dir: "dist/es",
format: "es",
sourcemap: false,
},
],
external: ["antd", "react", "react-dom"],
moduleContext: (id) => {
return "window";
},
plugins: [
resolve(),
external(),
image(),
url(),
svgr(),
postcss({
use: [["less", { javascriptEnabled: true }]],
// modules: true,
// plugins: [
// require("postcss-preset-env")({
// autoprefixer: {
// flexbox: "no-2009",
// },
// browsers: [
// ">0.15%",
// "last 4 versions",
// "Firefox ESR",
// "not ie < 9", // React doesn't support IE8 anyway
// "last 3 iOS versions",
// "iOS 7",
// "iOS >= 7",
// ],
// stage: 3,
// }),
// ],
}),
babel({
babelrc: false,
exclude: [/\/core-js\//, "node_modules/**"],
// babelHelpers:production ? "bundled" :"runtime",
babelHelpers: "bundled",
presets: [
[
"@babel/preset-env",
{
modules: false,
corejs: 2,
useBuiltIns: "usage",
targets: {
browsers: ["last 2 versions", "iOS >= 7", "Android >= 5"],
},
},
],
"@babel/preset-react",
],
plugins: [
[
"babel-plugin-named-asset-import",
{
loaderMap: {
svg: {
ReactComponent: "@svgr/webpack?-svgo![path]",
},
},
},
],
"@babel/plugin-proposal-object-rest-spread",
"@babel/plugin-syntax-dynamic-import",
[
"@babel/plugin-proposal-class-properties",
{
// loose: true,
},
],
// "react-loadable/babel",
"babel-plugin-transform-object-assign",
["@babel/plugin-proposal-decorators", { legacy: true }],
"@babel/plugin-proposal-optional-chaining",
// [
// "import",
// {
// libraryName: "antd",
// libraryDirectory: "es",
// // style: "css"
// style: true,
// },
// "ant",
// ],
],
}),
commonjs(),
production && terser(), // minify, but only in production
],
};
function deleteFolder(path) {
let files = [];
if (fs.existsSync(path)) {
files = fs.readdirSync(path);
files.forEach(function (file, index) {
let curPath = path + "/" + file;
if (fs.statSync(curPath).isDirectory()) {
deleteFolder(curPath);
} else {
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
}