@ixon-cdk/static-builder 1.0.0-alpha.0 → 1.0.0-alpha.12
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 +2 -2
- package/browser.js +54 -70
- package/index.js +16 -13
- package/package.json +3 -7
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
# IXON Component Development Kit
|
|
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 [
|
|
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
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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(
|
|
12
|
-
const outputDir = path.dirname(path.join(
|
|
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
|
-
|
|
15
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
42
|
+
// build
|
|
43
|
+
await build(config);
|
|
44
|
+
copyAssets(assets, inputDir, outputDir);
|
|
45
|
+
|
|
46
|
+
// watch source files
|
|
72
47
|
if (watch) {
|
|
73
|
-
|
|
74
|
-
|
|
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(
|
|
3
|
-
} catch {
|
|
2
|
+
require('module-alias/register');
|
|
3
|
+
} catch {
|
|
4
|
+
// do nothing
|
|
5
|
+
}
|
|
4
6
|
|
|
5
|
-
const fs = require(
|
|
6
|
-
const path = require(
|
|
7
|
-
const isPotentialCustomElementName = require(
|
|
8
|
-
const { getArgv, logErrorMessage } = require(
|
|
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
|
|
15
|
-
const output = argv.output ||
|
|
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
|
-
|
|
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(
|
|
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 ===
|
|
38
|
-
require(
|
|
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.
|
|
3
|
+
"version": "1.0.0-alpha.12",
|
|
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
|
-
"
|
|
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.
|
|
13
|
+
"@ixon-cdk/core": "^1.0.0-alpha.12"
|
|
18
14
|
}
|
|
19
15
|
}
|