@ixon-cdk/static-builder 1.0.0-alpha.1 → 1.0.0-alpha.10

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 CHANGED
@@ -1,3 +1,3 @@
1
- # IXON Component Development Kit HTMLElement Builder
1
+ # IXON Component Development Kit Static Builder
2
2
 
3
- This builder can be used with the IXON Component Development Kit (CDK). It contains build targets for building [webcomponents](https://developer.mozilla.org/en-US/docs/Web/Web_Components) (reusable custom elements) using [Rollup](https://rollupjs.org/guide/en/).
3
+ This builder can be used with the IXON Component Development Kit (CDK). It contains build targets for building [webcomponents](https://developer.mozilla.org/en-US/docs/Web/Web_Components) (reusable custom elements) using [Vite](https://vitejs.dev/).
package/browser.js CHANGED
@@ -1,77 +1,60 @@
1
- const fs = require("fs");
2
- const rollup = require("rollup");
3
- const commonjs = require("@rollup/plugin-commonjs");
4
- const { nodeResolve } = require("@rollup/plugin-node-resolve");
5
- const { terser } = require("rollup-plugin-terser");
6
1
  const path = require("path");
7
- const rimraf = require("rimraf");
8
- const { copyMetaFiles, watchMetaFiles } = require("@ixon-cdk/core");
2
+ const { build } = require("vite");
3
+ const {
4
+ getRootDir,
5
+ cleanDir,
6
+ watchInputDir,
7
+ writeDemoFile,
8
+ copyAssets,
9
+ watchAssets,
10
+ } = require("@ixon-cdk/core");
9
11
 
10
- async function _build(inputFile, outputFile, tag, production, watch) {
11
- const inputDir = path.dirname(path.join(process.cwd(), inputFile));
12
- const outputDir = path.dirname(path.join(process.cwd(), outputFile));
12
+ async function _build(inputFile, outputFile, tag, assets, production, watch) {
13
+ const inputDir = path.dirname(path.join(getRootDir(), inputFile));
14
+ const outputDir = path.dirname(path.join(getRootDir(), outputFile));
13
15
 
14
- // clean
15
- if (fs.existsSync(outputDir)) {
16
- rimraf.sync(outputDir);
17
- }
18
-
19
- // output folder
20
- fs.mkdirSync(outputDir, { recursive: true });
21
-
22
- // demo file
23
- const demoFileContent = `<meta charset="utf-8">\n<title>${tag} demo</title>\n<script src="./${path.basename(
24
- outputFile
25
- )}"></script>\n\n\n<${tag}></${tag}>\n\n`;
26
- fs.writeFileSync(`${outputDir}/demo.html`, demoFileContent, {
27
- encoding: "utf8",
28
- flag: "w",
29
- });
16
+ cleanDir(outputDir);
17
+ writeDemoFile(tag, outputDir, outputFile);
30
18
 
31
- // component
32
- const inputOptions = {
33
- input: inputFile,
34
- plugins: [nodeResolve({ browser: true, dedupe: ["svelte"] }), commonjs()],
35
- };
36
- const outputOptions = {
37
- sourcemap: true,
38
- format: "iife",
39
- name: "app",
40
- file: outputFile,
41
- };
42
- const productionOutputOptions = {
43
- ...outputOptions,
44
- file: outputFile,
45
- plugins: [terser()],
19
+ const config = {
20
+ root: getRootDir(),
21
+ mode: production ? "production" : "development",
22
+ build: {
23
+ lib: {
24
+ entry: inputFile,
25
+ formats: ["iife"],
26
+ name: "app",
27
+ fileName: () => `${tag}.min.js`,
28
+ },
29
+ sourcemap: true,
30
+ outDir: outputDir,
31
+ emptyOutDir: false,
32
+ rollupOptions: {
33
+ output: {
34
+ inlineDynamicImports: true,
35
+ },
36
+ },
37
+ },
38
+ write: true,
39
+ plugins: [],
46
40
  };
47
- if (watch) {
48
- const watchOptions = {
49
- ...inputOptions,
50
- output: production
51
- ? [outputOptions, productionOutputOptions]
52
- : [outputOptions],
53
- watch: { exclude: ["node_modules/**"] },
54
- };
55
- const watcher = await rollup.watch(watchOptions);
56
- watcher.close();
57
- } else {
58
- const bundle = await rollup.rollup(inputOptions);
59
- await bundle.generate(outputOptions);
60
- await bundle.write(outputOptions);
61
- if (production) {
62
- await bundle.generate(productionOutputOptions);
63
- await bundle.write(productionOutputOptions);
64
- }
65
- await bundle.close();
66
- }
67
41
 
68
- /**
69
- * Copy meta files (manifest and icon)
70
- */
71
- copyMetaFiles(inputDir, outputDir);
42
+ // build
43
+ await build(config);
44
+ copyAssets(assets, inputDir, outputDir);
45
+
46
+ // watch source files
72
47
  if (watch) {
73
- watchMetaFiles(inputDir, () => {
74
- copyMetaFiles(inputDir, outputDir);
48
+ watchAssets(assets, inputDir, outputDir);
49
+ await watchInputDir(inputDir, (isAsset) => {
50
+ if (isAsset) {
51
+ // do nothing
52
+ } else {
53
+ build(config);
54
+ }
55
+ });
56
+ process.on("SIGINT", () => {
57
+ process.exit();
75
58
  });
76
59
  }
77
60
  }
@@ -80,8 +63,9 @@ module.exports = function runBuild(
80
63
  inputFile,
81
64
  outputFile,
82
65
  tag,
66
+ assets,
83
67
  production = true,
84
68
  watch = false
85
69
  ) {
86
- return _build(inputFile, outputFile, tag, production, watch);
70
+ return _build(inputFile, outputFile, tag, assets, production, watch);
87
71
  };
package/index.js CHANGED
@@ -5,7 +5,7 @@ try {
5
5
  const fs = require("fs");
6
6
  const path = require("path");
7
7
  const isPotentialCustomElementName = require("is-potential-custom-element-name");
8
- const { getArgv, logErrorMessage } = require("@ixon-cdk/core");
8
+ const { getArgv, getRootDir, logErrorMessage } = require("@ixon-cdk/core");
9
9
 
10
10
  function main() {
11
11
  const argv = getArgv();
@@ -13,6 +13,7 @@ function main() {
13
13
  const tag = argv._[1];
14
14
  const input = argv.input;
15
15
  const output = argv.output || "dist/bundle/main.min.js";
16
+ const assets = JSON.parse(argv.assets || "[]");
16
17
  const watch = !!argv.watch;
17
18
 
18
19
  if (!input) {
@@ -22,7 +23,7 @@ function main() {
22
23
  process.exit();
23
24
  }
24
25
 
25
- if (!fs.existsSync(path.join(process.cwd(), input))) {
26
+ if (!fs.existsSync(path.join(getRootDir(), input))) {
26
27
  logErrorMessage(`Input file '${input}' does not exist.`);
27
28
  process.exit();
28
29
  }
@@ -35,7 +36,7 @@ function main() {
35
36
  }
36
37
 
37
38
  if (buildTarget === "browser") {
38
- require("./browser")(input, output, tag, true, watch);
39
+ require("./browser")(input, output, tag, assets, true, watch);
39
40
  }
40
41
  }
41
42
 
package/package.json CHANGED
@@ -1,19 +1,15 @@
1
1
  {
2
2
  "name": "@ixon-cdk/static-builder",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.0-alpha.10",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "",
7
7
  "license": "ISC",
8
8
  "dependencies": {
9
- "@rollup/plugin-commonjs": "^20.0.0",
10
- "@rollup/plugin-node-resolve": "^13.0.4",
11
9
  "is-potential-custom-element-name": "^1.0.1",
12
- "rimraf": "^3.0.2",
13
- "rollup": "^2.56.3",
14
- "rollup-plugin-terser": "^7.0.2"
10
+ "vite": "^2.6.12"
15
11
  },
16
12
  "peerDependencies": {
17
- "@ixon-cdk/core": "^1.0.0-alpha.1"
13
+ "@ixon-cdk/core": "^1.0.0-alpha.10"
18
14
  }
19
15
  }