@ixon-cdk/svelte-builder 1.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/browser.js +118 -0
- package/index.js +42 -0
- package/package.json +25 -0
package/README.md
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# IXON Component Development Kit Svelte Builder
|
|
2
|
+
|
|
3
|
+
This builder can be used with the IXON Component Development Kit (CDK). It contains build targets for compiling [Svelte](https://svelte.dev/) components into [webcomponents](https://developer.mozilla.org/en-US/docs/Web/Web_Components) (reusable custom elements) using [Rollup](https://github.com/sveltejs/rollup-plugin-svelte).
|
package/browser.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const rollup = require("rollup");
|
|
3
|
+
const preprocess = require("svelte-preprocess");
|
|
4
|
+
const commonjs = require("@rollup/plugin-commonjs");
|
|
5
|
+
const { nodeResolve } = require("@rollup/plugin-node-resolve");
|
|
6
|
+
const svelte = require("rollup-plugin-svelte");
|
|
7
|
+
const { terser } = require("rollup-plugin-terser");
|
|
8
|
+
const path = require("path");
|
|
9
|
+
const rimraf = require("rimraf");
|
|
10
|
+
const { copyMetaFiles, watchMetaFiles, pascalCase } = require("@ixon-cdk/core");
|
|
11
|
+
|
|
12
|
+
async function _build(inputFile, outputFile, tag, production, watch) {
|
|
13
|
+
const inputDir = path.dirname(path.join(process.cwd(), inputFile));
|
|
14
|
+
const outputDir = path.dirname(path.join(process.cwd(), outputFile));
|
|
15
|
+
|
|
16
|
+
// temporary entry file
|
|
17
|
+
const entryFileName = path.join(
|
|
18
|
+
path.dirname(require.resolve("@ixon-cdk/svelte-builder")),
|
|
19
|
+
`__temp_entry-${tag}.js`
|
|
20
|
+
);
|
|
21
|
+
const componentStatic = pascalCase(tag);
|
|
22
|
+
const entryFileContent = `import ${componentStatic} from '../../${inputFile}';\nexport default new ${componentStatic}();\n`;
|
|
23
|
+
fs.writeFileSync(entryFileName, entryFileContent, {
|
|
24
|
+
encoding: "utf8",
|
|
25
|
+
flag: "w",
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// clean
|
|
29
|
+
if (fs.existsSync(outputDir)) {
|
|
30
|
+
rimraf.sync(outputDir);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// output folder
|
|
34
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
35
|
+
|
|
36
|
+
// demo file
|
|
37
|
+
const demoFileContent = `<meta charset="utf-8">\n<title>${tag} demo</title>\n<script src="./${path.basename(
|
|
38
|
+
outputFile
|
|
39
|
+
)}"></script>\n\n\n<${tag}></${tag}>\n\n`;
|
|
40
|
+
fs.writeFileSync(`${outputDir}/demo.html`, demoFileContent, {
|
|
41
|
+
encoding: "utf8",
|
|
42
|
+
flag: "w",
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// component
|
|
46
|
+
const inputOptions = {
|
|
47
|
+
input: entryFileName,
|
|
48
|
+
plugins: [
|
|
49
|
+
svelte({
|
|
50
|
+
compilerOptions: {
|
|
51
|
+
customElement: true,
|
|
52
|
+
dev: !production,
|
|
53
|
+
immutable: true,
|
|
54
|
+
tag: tag,
|
|
55
|
+
},
|
|
56
|
+
preprocess: preprocess(),
|
|
57
|
+
}),
|
|
58
|
+
nodeResolve({ browser: true, dedupe: ["svelte"] }),
|
|
59
|
+
commonjs(),
|
|
60
|
+
],
|
|
61
|
+
};
|
|
62
|
+
const outputOptions = {
|
|
63
|
+
sourcemap: true,
|
|
64
|
+
format: "iife",
|
|
65
|
+
name: "app",
|
|
66
|
+
file: outputFile,
|
|
67
|
+
};
|
|
68
|
+
const productionOutputOptions = {
|
|
69
|
+
...outputOptions,
|
|
70
|
+
file: outputFile,
|
|
71
|
+
plugins: [terser()],
|
|
72
|
+
};
|
|
73
|
+
if (watch) {
|
|
74
|
+
const watchOptions = {
|
|
75
|
+
...inputOptions,
|
|
76
|
+
output: production
|
|
77
|
+
? [outputOptions, productionOutputOptions]
|
|
78
|
+
: [outputOptions],
|
|
79
|
+
watch: { exclude: ["node_modules/**"] },
|
|
80
|
+
};
|
|
81
|
+
const watcher = await rollup.watch(watchOptions);
|
|
82
|
+
watcher.close();
|
|
83
|
+
process.on("SIGINT", () => {
|
|
84
|
+
fs.unlinkSync(entryFileName);
|
|
85
|
+
process.exit();
|
|
86
|
+
});
|
|
87
|
+
} else {
|
|
88
|
+
const bundle = await rollup.rollup(inputOptions);
|
|
89
|
+
await bundle.generate(outputOptions);
|
|
90
|
+
await bundle.write(outputOptions);
|
|
91
|
+
if (production) {
|
|
92
|
+
await bundle.generate(productionOutputOptions);
|
|
93
|
+
await bundle.write(productionOutputOptions);
|
|
94
|
+
}
|
|
95
|
+
await bundle.close();
|
|
96
|
+
fs.unlinkSync(entryFileName);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Copy meta files (manifest and icon)
|
|
101
|
+
*/
|
|
102
|
+
copyMetaFiles(inputDir, outputDir);
|
|
103
|
+
if (watch) {
|
|
104
|
+
watchMetaFiles(inputDir, () => {
|
|
105
|
+
copyMetaFiles(inputDir, outputDir);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
module.exports = function runBuild(
|
|
111
|
+
inputFile,
|
|
112
|
+
outputFile,
|
|
113
|
+
tag,
|
|
114
|
+
production = true,
|
|
115
|
+
watch = false
|
|
116
|
+
) {
|
|
117
|
+
return _build(inputFile, outputFile, tag, production, watch);
|
|
118
|
+
};
|
package/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
try {
|
|
2
|
+
require("module-alias/register");
|
|
3
|
+
} catch {}
|
|
4
|
+
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const isPotentialCustomElementName = require("is-potential-custom-element-name");
|
|
8
|
+
const { getArgv, logErrorMessage } = require("@ixon-cdk/core");
|
|
9
|
+
|
|
10
|
+
function main() {
|
|
11
|
+
const argv = getArgv();
|
|
12
|
+
const buildTarget = argv._[0];
|
|
13
|
+
const tag = argv._[1];
|
|
14
|
+
const input = argv.input;
|
|
15
|
+
const output = argv.output || "dist/bundle/main.min.js";
|
|
16
|
+
const watch = !!argv.watch;
|
|
17
|
+
|
|
18
|
+
if (!input) {
|
|
19
|
+
logErrorMessage(
|
|
20
|
+
"Must supply an input file, relative to the workspace root."
|
|
21
|
+
);
|
|
22
|
+
process.exit();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (!fs.existsSync(path.join(process.cwd(), input))) {
|
|
26
|
+
logErrorMessage(`Input file '${input}' does not exist.`);
|
|
27
|
+
process.exit();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!isPotentialCustomElementName(tag)) {
|
|
31
|
+
logErrorMessage(
|
|
32
|
+
`Custom element name '${tag}' is invalid. See https://html.spec.whatwg.org/multipage/custom-elements.html#prod-potentialcustomelementname`
|
|
33
|
+
);
|
|
34
|
+
process.exit();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (buildTarget === "browser") {
|
|
38
|
+
require("./browser")(input, output, tag, true, watch);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
main();
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ixon-cdk/svelte-builder",
|
|
3
|
+
"version": "1.0.0-alpha.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"author": "",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@rollup/plugin-commonjs": "^20.0.0",
|
|
10
|
+
"@rollup/plugin-node-resolve": "^13.0.4",
|
|
11
|
+
"is-potential-custom-element-name": "^1.0.1",
|
|
12
|
+
"node-sass": "^6.0.1",
|
|
13
|
+
"rimraf": "^3.0.2",
|
|
14
|
+
"rollup": "^2.56.3",
|
|
15
|
+
"rollup-plugin-css-only": "^3.1.0",
|
|
16
|
+
"rollup-plugin-livereload": "^2.0.5",
|
|
17
|
+
"rollup-plugin-svelte": "^7.1.0",
|
|
18
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
19
|
+
"svelte": "^3.42.6",
|
|
20
|
+
"svelte-preprocess": "^4.9.4"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"@ixon-cdk/core": "^1.0.0-alpha.0"
|
|
24
|
+
}
|
|
25
|
+
}
|