-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
107 lines (102 loc) · 2.89 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
import path from "path";
import fs from "fs";
import alias from "rollup-plugin-alias";
import babel from "rollup-plugin-babel";
import commonjs from "rollup-plugin-commonjs";
import resolve from "rollup-plugin-node-resolve";
import ts from "rollup-plugin-typescript2";
import uglify from "rollup-plugin-uglify";
import { minify as minify_es } from "uglify-es";
const r = (filepath, encoding = "utf8") =>
JSON.parse(fs.readFileSync(filepath, { encoding }));
const { version } = r("package.json");
const dev = process.env.NODE_ENV === "dev";
const bundle = process.argv.includes("--bundle");
const commonPlugins = [
alias({
relativeTimeLabel: path.resolve(".", "src/index"),
functions: path.resolve(".", "src/functions"),
helpers: path.resolve(".", "src/helpers"),
types: path.resolve(".", "src/types")
}),
// ts({}),
babel({
exclude: "node_modules/**"
}),
commonjs({
include: ["node_modules/**"],
exclude: ["node_modules/process-es6/**"],
namedExports: {
"node_modules/prop-types/index.js": ["PropTypes"],
"node_modules/react/index.js": ["Component"],
"node_modules/react-dom/index.js": ["render"]
}
}),
resolve()
];
const config = {
input: "./src/index.jsx",
output: [
{
file: "dist/relativeTimeLabel.cjs.js",
format: "cjs",
name: "RelativeTimeLabel",
banner: `/** relativeTimeLabel v${version} : commonjs bundle **/`,
exports: "named"
},
{
file: "dist/relativeTimeLabel.esm.js",
format: "es",
name: "RelativeTimeLabel",
banner: `/** relativeTimeLabel v${version} : es bundle **/`
},
{
file: "dist/relativeTimeLabel.js",
format: "iife",
name: "RelativeTimeLabel",
banner: `/** relativeTimeLabel v${version} : iife bundle **/`
}
],
plugins: [...commonPlugins, bundle && uglify({}, minify_es)],
external: [
"react",
"react-dom",
"prop-types",
path.resolve("./src/types.d.ts")
]
};
const devConfig = {
input: "./src/index.jsx",
output: [
{
file: "dist/relativeTimeLabel.dev.cjs.js",
format: "cjs",
name: "RelativeTimeLabel",
banner: `/** relativeTimeLabel v${version} : commonjs bundle **/\n/** DEVELOPMENT FILE **/`,
exports: "named",
sourcemap: "./dist/"
},
{
file: "dist/relativeTimeLabel.dev.esm.js",
format: "es",
name: "RelativeTimeLabel",
banner: `/** relativeTimeLabel v${version} : es bundle **/\n/** DEVELOPMENT FILE **/`,
sourcemap: "./dist/"
},
{
file: "dist/relativeTimeLabel.dev.js",
format: "iife",
name: "RelativeTimeLabel",
banner: `/** relativeTimeLabel v${version} : iife bundle **/\n/** DEVELOPMENT FILE **/`,
sourcemap: "./dist/"
}
],
plugins: [...commonPlugins],
external: [
"react",
"react-dom",
"prop-types",
path.resolve("./src/types.d.ts")
]
};
export default [config, devConfig];