forked from Anidetrix/rollup-plugin-styles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
73 lines (69 loc) · 2.09 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
import { readdirSync } from "fs-extra";
import { terser } from "rollup-plugin-terser";
import { babel } from "@rollup/plugin-babel";
import commonjs from "@rollup/plugin-commonjs";
import dts from "rollup-plugin-dts";
import externals from "rollup-plugin-node-externals";
import json from "@rollup/plugin-json";
import replace from "@rollup/plugin-replace";
import resolve from "@rollup/plugin-node-resolve";
import typescript from "@rollup/plugin-typescript";
import pkg from "./package.json";
const extensions = [".ts", ".mjs", ".js", ".cjs", ".json"];
/** @type {import('rollup').RollupOptions[]} */
const config = [
// Bundle
{
input: "./src/index.ts",
output: [
{ format: "cjs", file: pkg.exports.require, exports: "default" },
{ format: "es", file: pkg.exports.import, exports: "default" },
],
plugins: [
externals({ deps: true }),
replace({
preventAssignment: true,
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
}),
json(),
resolve({ preferBuiltins: true, extensions }),
commonjs(),
typescript(),
babel({ babelHelpers: "bundled", extensions }),
],
},
// Injector
{
input: "./runtime/inject-css.js",
output: { format: "es", file: "./dist/runtime/inject-css.js" },
plugins: [
externals({ deps: true }),
json(),
resolve({ preferBuiltins: true }),
commonjs(),
babel({
babelHelpers: "bundled",
configFile: false,
presets: [["@babel/preset-env", { modules: false, targets: { ie: "8" } }]],
}),
terser({ format: { comments: false }, ie8: true, safari10: true }),
],
},
// Declaration
{
input: "./src/index.ts",
output: { format: "es", file: pkg.types },
plugins: [
externals({ deps: true }),
dts({ respectExternal: true }),
{
name: "shims",
banner: readdirSync(`${__dirname}/src/shims`)
.map(s => s.replace(/\.ts$/, "").replace(/\.d$/, ""))
.map(s => `/// <reference types="./shims/${s}" />`)
.join("\n"),
},
],
},
];
export default config;