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

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.
Files changed (4) hide show
  1. package/README.md +2 -2
  2. package/browser.js +54 -70
  3. package/index.js +16 -13
  4. package/package.json +3 -7
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
- const path = require("path");
7
- const rimraf = require("rimraf");
8
- const { copyMetaFiles, watchMetaFiles } = require("@ixon-cdk/core");
1
+ const path = require('path');
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
- watch = false
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
@@ -1,41 +1,44 @@
1
1
  try {
2
- require("module-alias/register");
3
- } catch {}
2
+ require('module-alias/register');
3
+ } catch {
4
+ // do nothing
5
+ }
4
6
 
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");
7
+ const fs = require('fs');
8
+ const path = require('path');
9
+ const isPotentialCustomElementName = require('is-potential-custom-element-name');
10
+ const { getArgv, getRootDir, logErrorMessage } = require('@ixon-cdk/core');
9
11
 
10
12
  function main() {
11
13
  const argv = getArgv();
12
14
  const buildTarget = argv._[0];
13
15
  const tag = argv._[1];
14
- const input = argv.input;
15
- const output = argv.output || "dist/bundle/main.min.js";
16
+ const { input } = argv;
17
+ const output = argv.output || 'dist/bundle/main.min.js';
18
+ const assets = JSON.parse(argv.assets || '[]');
16
19
  const watch = !!argv.watch;
17
20
 
18
21
  if (!input) {
19
22
  logErrorMessage(
20
- "Must supply an input file, relative to the workspace root."
23
+ 'Must supply an input file, relative to the workspace root.',
21
24
  );
22
25
  process.exit();
23
26
  }
24
27
 
25
- if (!fs.existsSync(path.join(process.cwd(), input))) {
28
+ if (!fs.existsSync(path.join(getRootDir(), input))) {
26
29
  logErrorMessage(`Input file '${input}' does not exist.`);
27
30
  process.exit();
28
31
  }
29
32
 
30
33
  if (!isPotentialCustomElementName(tag)) {
31
34
  logErrorMessage(
32
- `Custom element name '${tag}' is invalid. See https://html.spec.whatwg.org/multipage/custom-elements.html#prod-potentialcustomelementname`
35
+ `Custom element name '${tag}' is invalid. See https://html.spec.whatwg.org/multipage/custom-elements.html#prod-potentialcustomelementname`,
33
36
  );
34
37
  process.exit();
35
38
  }
36
39
 
37
- if (buildTarget === "browser") {
38
- require("./browser")(input, output, tag, true, watch);
40
+ if (buildTarget === 'browser') {
41
+ require('./browser')(input, output, tag, assets, true, watch);
39
42
  }
40
43
  }
41
44
 
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.13",
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.13"
18
14
  }
19
15
  }