forked from andreasbm/weightless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.ts
164 lines (158 loc) · 3.95 KB
/
rollup.config.ts
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
161
162
163
import { copy, defaultExternals, defaultOutputConfig, defaultPlugins, defaultProdPlugins, defaultServePlugins, isLibrary, isProd, isServe, workbox } from "@appnest/web-config";
import { join, resolve } from "path";
import pkg from "./package.json";
const folders = {
src: resolve(__dirname, "src/demo"),
dist: resolve(__dirname, "dist"),
assets: resolve(__dirname, "assets"),
dist_assets: resolve(__dirname, "dist/assets")
};
const files = {
main: join(folders.src, "main.ts"),
src_index: join(folders.src, "index.html"),
src_robots: join(folders.src, "robots.txt"),
src_sw_extension: join(folders.src, "sw-extension.js"),
dist_sw_extension: join(folders.dist, "sw-extension.js"),
dist_index: join(folders.dist, "index.html"),
dist_robots: join(folders.dist, "robots.txt"),
dist_service_worker: join(folders.dist, "sw.js")
};
export default [
{
// Module build
input: {
main: files.main
},
output: [
defaultOutputConfig({
format: "system",
dir: folders.dist
})
],
plugins: [
...defaultPlugins({
cleanConfig: {
targets: [
folders.dist
]
},
copyConfig: {
resources: [
[folders.assets, folders.dist_assets]
]
},
htmlTemplateConfig: {
template: files.src_index,
scriptType: "text/javascript",
target: files.dist_index,
transformScript: (({filename}) => `<script>System.import("/${filename}");</script>`),
include: /main(-.*)?\.js$/,
polyfillConfig: {
features: ["systemjs", "web-components"]
}
},
importStylesConfig: {
globals: ["main.scss"]
}
}),
// Serve
...(isServe ? [
...defaultServePlugins({
serveConfig: {
port: 1350,
contentBase: folders.dist
},
livereloadConfig: {
watch: folders.dist,
port: 35731
}
})
] : []),
// Production
...(isProd ? [
...defaultProdPlugins({
dist: folders.dist,
minifyLitHtmlConfig: {
verbose: false,
// Exclude all files since we need the original formatting for the demo code blocks
exclude: /.*/
},
compressConfig: {
// Exclude everything since firebase compresses the files for us
exclude: /.*/
}
}),
copy({
resources: [
[files.src_robots, files.dist_robots],
[files.src_sw_extension, files.dist_sw_extension]
]
}),
workbox({
mode: "generateSW",
workboxConfig: {
globDirectory: folders.dist,
swDest: files.dist_service_worker,
globPatterns: [`**/*.{js,png,html,css}`],
importScripts: [`sw-extension.js`],
runtimeCaching: [{
urlPattern: /.*/,
handler: "NetworkFirst"
}]
}
})
] : [])
],
external: [
...(isLibrary ? [
...defaultExternals(pkg)
] : [])
],
treeshake: isProd,
context: "window"
}
// !isServe && isProd ? {
// // CJS build
// input: {
// main: files.main
// },
// output: [
// defaultOutputConfig({
// format: "cjs",
// dir: folders.dist,
// entryFileNames: "[name]-legacy-[hash].js",
// chunkFileNames: "[name]-legacy-[hash].js",
// })
// ],
// plugins: [
// ...defaultPlugins({
// htmlTemplateConfig: {
// template: files.dist_index,
// target: files.dist_index,
// scriptType: "text/javascript",
// transformScript: ({filename, scriptType}) => `<script nomodule type="${scriptType}" src="${filename}"></script>`,
// include: /main(-.*)?\.js$/
// },
// importStylesConfig: {
// globals: ["main.scss"]
// }
// }),
// ...defaultProdPlugins({
// dist: folders.dist,
// minifyLitHtmlConfig: {
// verbose: false,
// // Exclude all files since we need the original formatting for the demo code blocks
// exclude: /.*/
// }
// }),
// copy({
// resources: [
// [files.src_robots, files.dist_robots],
// [files.src_sw_extension, files.dist_sw_extension]
// ]
// })
// ],
// treeshake: isProd,
// context: "window"
// } : undefined
];