-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrollup.demo.config.js
68 lines (66 loc) · 1.94 KB
/
rollup.demo.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
import typescript from "rollup-plugin-typescript2";
import copy from "rollup-plugin-copy";
import resolve from "rollup-plugin-node-resolve";
import gzip from "rollup-plugin-gzip";
import { terser } from "rollup-plugin-terser";
import svelte from "rollup-plugin-svelte";
import postcss from 'rollup-plugin-postcss';
import { promises as fs } from "fs";
import * as Prism from 'prismjs';
import 'prismjs/components/prism-javascript';
const SOURCE_PREFIX = "source:";
const SOURCE_SUFFIX = ".src";
const demoSourceCodePlugin = {
async load(id) {
if (id.startsWith(SOURCE_PREFIX) && id.endsWith(SOURCE_SUFFIX)) {
const fileId = id.substring(
SOURCE_PREFIX.length,
id.length - SOURCE_SUFFIX.length
);
let source = await fs.readFile(fileId, "utf8");
source = source.replace(/^[\s\S]*(async function animation)/, '$1');
source = source.replace(/<\/script>[\s\S]*$/, '');
source = Prism.highlight(source, Prism.languages.javascript, 'javascript');
return `export default ${JSON.stringify(source)};`;
}
return null;
},
async resolveId(id, importer) {
if (id.startsWith(SOURCE_PREFIX)) {
const fileId = id.substr(SOURCE_PREFIX.length);
const resolveResult = await this.resolve(fileId, importer);
return SOURCE_PREFIX + resolveResult.id + SOURCE_SUFFIX;
}
return null;
}
};
export default {
input: "src/demo/main.ts",
output: {
file: "dist/demo/demo.js",
sourcemap: true,
format: "iife"
},
plugins: [
demoSourceCodePlugin,
copy({
targets: [{ src: "src/demo/index.html", dest: "dist/demo/" }]
}),
resolve({
mainFields: ["module"],
extensions: [".mjs", ".js", ".ts", ".svelte"]
}),
typescript({
objectHashIgnoreUnknownHack: true,
tsconfig: "tsconfig.demo.json"
}),
svelte({
css: function(css) {
css.write("dist/demo/demo.css");
}
}),
postcss(),
terser(),
gzip()
]
};