-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrollup.config.mjs
160 lines (152 loc) · 3.66 KB
/
rollup.config.mjs
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import typescript from "rollup-plugin-typescript2";
import resolve from "@rollup/plugin-node-resolve";
import postcss from "rollup-plugin-postcss";
import litcss from "rollup-plugin-postcss-lit";
import replace from "@rollup/plugin-replace";
import { visualizer } from "rollup-plugin-visualizer";
import glob from "glob";
import path from "node:path";
import { fileURLToPath } from "node:url";
import copy from 'rollup-plugin-copy'
import preserveDirectives from "rollup-plugin-preserve-directives";
const external = [
"@lit",
"lit",
"lit-element",
"@popperjs",
/@open-wc\/.*/,
"bootstrap",
"tslib",
/lit\/.*/,
/bootstrap\/.*/,
"imask",
"date-fns",
];
const copyPlugin = copy({
targets: [
{src: "src/themes/**/*", dest: "lib/themes"}
]
})
const wcPlugins = [
resolve({
browser: true,
dedupe: external,
exportConditions: ["development"]
}),
replace({
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
preventAssignment: true
}),
postcss({
minimize: true,
inject: false,
}),
litcss(),
typescript({
tsconfig: "tsconfig.json",
useTsconfigDeclarationDir: true
}),
visualizer()
];
const reactBuildPlugins = [
resolve(),
postcss({
minimize: true,
inject: false
}),
litcss(),
typescript({
useTsconfigDeclarationDir: true
}),
preserveDirectives()
];
const buildUMDComponentBundles = () => {
const indexFilesMetadata = glob
.sync("src/components/**/index.ts")
.map(file => ({
name: file.split("/")[2],
outputPath: path.relative("src", file.slice(0, file.length - path.extname(file).length)),
inputPath: fileURLToPath(new URL(file, import.meta.url))
}))
.flat();
return indexFilesMetadata.map(meta => ({
input: meta.inputPath,
output: {
name: `${meta.name}Bundle`,
file: `lib/${meta.outputPath}.umd.js`,
format: "umd",
sourcemap: true
},
plugins: wcPlugins
}));
};
const buildSgdsPackage = () => {
const esmModules = [
//generate subpath entry points for individual components side effects ce file
{
input: ["src/index.ts", "src/components/index.ts"],
output: {
entryFileNames: "[name].js",
dir: "lib",
format: "esm",
sourcemap: true,
preserveModules: true,
preserveModulesRoot: "src"
},
plugins: [...wcPlugins, copyPlugin],
external
}
];
const umdBundles = [
// bundled form for cdn
{
input: ["src/index.ts"],
output: {
entryFileNames: "[name].umd.js",
dir: "lib",
format: "umd",
sourcemap: true
},
plugins: wcPlugins
},
...buildUMDComponentBundles()
];
const reactPackage = [
{
input: "src/react/index.ts",
output: [
{
entryFileNames: "[name].js",
dir: "lib/react",
format: "esm",
sourcemap: true,
exports: "named",
preserveModules: true,
preserveModulesRoot: "src/react",
banner: `'use client';`,
}
],
plugins: [...reactBuildPlugins],
external: ["@lit-labs/react", "react", ...external]
},
{
input: "src/react/index.ts",
output: [
{
entryFileNames: "[name].cjs.js",
dir: "lib/react",
format: "cjs",
sourcemap: true,
exports: "named",
preserveModules: true,
preserveModulesRoot: "src/react",
banner: `'use client';`,
}
],
plugins: [...reactBuildPlugins],
external: ["@lit-labs/react", "react", ...external]
}
];
return [...reactPackage, ...esmModules, ...umdBundles ];
};
export default buildSgdsPackage;