This repository was archived by the owner on Oct 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
47 lines (40 loc) · 1.38 KB
/
index.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
import { Platform, PlatformResult, StaticOptions } from 'compiler/interfaces';
import { Plugin } from 'rollup';
import command from 'rollup-plugin-command';
import nodePath from 'path';
import { writeTemplate } from '../../compiler/utils/plugin-common';
const www = (options: StaticOptions = {}): Platform => buildOptions => {
if (!options.run) options.run = {};
options = {
bundlePath: options.bundlePath || `bundle.js`,
tag: options.tag || `www`,
isSandboxed: options.isSandboxed,
run: {
action: options.run.action, // This can be undefined
options: options.run.options || {
exitOnFail: !buildOptions.watch.enable,
},
},
writeIndexHtml: options.writeIndexHtml === undefined ? true : options.writeIndexHtml,
};
const dummyPlugin: Plugin = {
name: `www-platform`,
};
const plugin: Plugin = {
name: `www-platform`,
buildStart: async () => {
await writeTemplate(nodePath.join(buildOptions.outDir, options.tag), { appEntry: options.bundlePath });
},
};
const platform: PlatformResult = {
tag: options.tag,
isSandboxed: () => options.isSandboxed,
bundlePath: () => options.bundlePath,
runtimePath: () => `.runtime.js`,
plugin: () => (options.writeIndexHtml ? plugin : dummyPlugin),
assetsPath: () => ``,
run: () => (options.run.action ? command(options.run.action, options.run.options) : dummyPlugin),
};
return platform;
};
export default www;