@cilix/lightjs 0.0.6 → 0.0.7
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/core.js +5 -4
- package/index.js +12 -2
- package/package.json +1 -1
package/core.js
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
|
|
22
22
|
module.exports = (config, fs, path) => {
|
|
23
23
|
const _files = {};
|
|
24
|
-
let includeRuntime
|
|
24
|
+
let includeRuntime;
|
|
25
25
|
|
|
26
26
|
function throw_error (err) {
|
|
27
27
|
err.origin = 'light';
|
|
@@ -1564,8 +1564,8 @@ module.exports = (config, fs, path) => {
|
|
|
1564
1564
|
} else {
|
|
1565
1565
|
node.children.forEach(walk);
|
|
1566
1566
|
if (node.data.name === 'head') {
|
|
1567
|
-
if (
|
|
1568
|
-
emit('<script>');
|
|
1567
|
+
if (js) {
|
|
1568
|
+
emit('<script type="module">');
|
|
1569
1569
|
emit(`document.addEventListener('DOMContentLoaded', function () {\n`);
|
|
1570
1570
|
emit(`(function (data){${js}})(${JSON.stringify(initial_state)})`);
|
|
1571
1571
|
emit('});');
|
|
@@ -2758,10 +2758,11 @@ module.exports = (config, fs, path) => {
|
|
|
2758
2758
|
};
|
|
2759
2759
|
|
|
2760
2760
|
const renderToAst = async (file, actions, _fileText) => {
|
|
2761
|
+
includeRuntime = false;
|
|
2761
2762
|
const fileText = file === 'default' ? _fileText : openFile(file);
|
|
2762
2763
|
const tokens = tokenize(fileText, file);
|
|
2763
2764
|
const ast = parse(tokens);
|
|
2764
|
-
let js
|
|
2765
|
+
let js;
|
|
2765
2766
|
if (includeRuntime) {
|
|
2766
2767
|
const runtime = generateRuntime(ast, actions);
|
|
2767
2768
|
|
package/index.js
CHANGED
|
@@ -53,6 +53,14 @@ const addParentPaths = (code, p) => {
|
|
|
53
53
|
return out;
|
|
54
54
|
};
|
|
55
55
|
|
|
56
|
+
const hideDynamicImports = (code) => {
|
|
57
|
+
return code.split('import(').join('__IMPORT_PLACEHOLDER__(');
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const restoreDynamicImports = (code) => {
|
|
61
|
+
return code.split('__IMPORT_PLACEHOLDER__(').join('import(');
|
|
62
|
+
};
|
|
63
|
+
|
|
56
64
|
const esbuild_to_light_error = (e, chunk) => {
|
|
57
65
|
let row = e.location.line - 1;
|
|
58
66
|
let col = e.location.column;
|
|
@@ -88,7 +96,8 @@ Light.compile = async (name, opts) => {
|
|
|
88
96
|
jsTransform: async (chunk) => {
|
|
89
97
|
try {
|
|
90
98
|
const opts = { format: 'cjs', loader: 'ts' };
|
|
91
|
-
const
|
|
99
|
+
const codeChunk = hideDynamicImports(chunk.code);
|
|
100
|
+
const result = await esbuild.transform(codeChunk, opts);
|
|
92
101
|
return addParentPaths(result.code, chunk.parent_dir);
|
|
93
102
|
} catch (e) {
|
|
94
103
|
e.origin = 'esbuild';
|
|
@@ -106,7 +115,8 @@ Light.compile = async (name, opts) => {
|
|
|
106
115
|
minify: opts.minify,
|
|
107
116
|
write: false
|
|
108
117
|
});
|
|
109
|
-
|
|
118
|
+
const output = restoreDynamicImports(result.outputFiles[0].text);
|
|
119
|
+
return output;
|
|
110
120
|
}
|
|
111
121
|
}, fs, path);
|
|
112
122
|
try {
|