vaderjs 1.3.3-alpha-81 → 1.3.3-alpha-83
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/package.json +1 -1
- package/vader.js +48 -43
package/package.json
CHANGED
package/vader.js
CHANGED
|
@@ -25,8 +25,10 @@ Object.keys(dirs).map((key, index) => {
|
|
|
25
25
|
}
|
|
26
26
|
}).filter(Boolean)[0]
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
if(process.env.isCloudflare){
|
|
29
|
+
let htmlFile = fs.readFileSync(process.cwd() + "/node_modules/vaderjs/runtime/index.html", 'utf8')
|
|
30
|
+
fs.writeFileSync(process.cwd() + "/dist/index.html", htmlFile)
|
|
31
|
+
}
|
|
30
32
|
|
|
31
33
|
function Compiler(func, file) {
|
|
32
34
|
let string = func;
|
|
@@ -612,48 +614,54 @@ function Compiler(func, file) {
|
|
|
612
614
|
let newImport = ''
|
|
613
615
|
let name = match.split('import')[1].split('from')[0].trim()
|
|
614
616
|
|
|
615
|
-
|
|
616
|
-
path
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
path = path.replace(';', '')
|
|
621
|
-
path = path.replace(/'/g, '').trim().replace(/"/g, '').trim()
|
|
622
|
-
path = path.replaceAll('.jsx', '.js');
|
|
623
|
-
path = path.replaceAll('../', '');
|
|
624
|
-
|
|
625
|
-
let css = fs.readFileSync(process.cwd() + '/' + path, 'utf8')
|
|
626
|
-
|
|
627
|
-
css = css.replaceAll('.', '')
|
|
628
|
-
newImport = `let ${name} = ${JSON.stringify(parse(css))}`
|
|
629
|
-
string = string.replace(beforeimport, newImport)
|
|
630
|
-
} else {
|
|
631
|
-
let beforePath = path
|
|
632
|
-
let deep = path.split('/').length - 1
|
|
633
|
-
for (let i = 0; i < deep; i++) {
|
|
634
|
-
path = path.split('../').join('')
|
|
635
|
-
path = path.split('./').join('')
|
|
636
|
-
}
|
|
637
|
-
path = path.replace(/'/g, '').trim().replace(/"/g, '').trim()
|
|
638
|
-
// remove double / from path
|
|
639
|
-
path = path.split('//').join('/')
|
|
640
|
-
if (!path.startsWith('./') && !path.includes('/vader.js') && !path.startsWith('src') && !path.startsWith('public')) {
|
|
641
|
-
path.includes('src') ? path.split('src')[1] : null
|
|
642
|
-
path = '/src/' + path
|
|
643
|
-
} else if (path.startsWith('src') || path.startsWith('public')) {
|
|
644
|
-
path = '/' + path
|
|
645
|
-
}
|
|
646
|
-
console.log(path)
|
|
647
|
-
path = path.replaceAll('.jsx', '.js');
|
|
648
|
-
|
|
617
|
+
switch (true) {
|
|
618
|
+
case path && path.includes('json'):
|
|
619
|
+
path = path.replace(';', '')
|
|
620
|
+
newImport = `let ${name} = await fetch('${path}').then(res => res.json())`
|
|
649
621
|
|
|
650
|
-
|
|
622
|
+
break;
|
|
623
|
+
case path && path.includes('module.css'):
|
|
624
|
+
let css = fs.readFileSync(process.cwd() + path, 'utf8')
|
|
625
|
+
css = css.replaceAll('.', '')
|
|
626
|
+
newImport = `let ${name} = ${JSON.stringify(parse(css))}`
|
|
627
|
+
break;
|
|
628
|
+
case path && path.includes('.css'):
|
|
629
|
+
newImport = ``
|
|
630
|
+
break;
|
|
631
|
+
default:
|
|
632
|
+
let beforePath = path
|
|
633
|
+
let deep = path.split('/').length - 1
|
|
634
|
+
for (let i = 0; i < deep; i++) {
|
|
635
|
+
path = path.split('../').join('')
|
|
636
|
+
path = path.split('./').join('')
|
|
637
|
+
}
|
|
638
|
+
path = path.replace(/'/g, '').trim().replace(/"/g, '').trim()
|
|
639
|
+
// remove double / from path
|
|
640
|
+
path = path.split('//').join('/')
|
|
641
|
+
if (!path.startsWith('./') && !path.includes('/vader.js') && !path.startsWith('src') && !path.startsWith('public')) {
|
|
642
|
+
path.includes('src') ? path.split('src')[1] : null
|
|
643
|
+
path = '/src/' + path
|
|
644
|
+
} else if (path.startsWith('src') || path.startsWith('public')) {
|
|
645
|
+
path = '/' + path
|
|
646
|
+
}
|
|
647
|
+
console.log(path)
|
|
648
|
+
path = path.replaceAll('.jsx', '.js');
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
string = string.replace(beforePath, "'" + path + "'")
|
|
652
|
+
break;
|
|
653
|
+
|
|
651
654
|
}
|
|
655
|
+
|
|
652
656
|
let html = fs.existsSync(process.cwd() + '/dist/index.html') ? fs.readFileSync(process.cwd() + '/dist/index.html', 'utf8') : ''
|
|
653
657
|
if (!html.includes(`<link rel="preload" href="${path.replace(/'/g, '').trim()}" as="${path.replace(/'/g, '').trim().includes('.css') ? 'style' : 'script'}">`)
|
|
654
|
-
&& !path.includes('.module.css')
|
|
658
|
+
&& !path.includes('.module.css')
|
|
655
659
|
) {
|
|
656
|
-
let preload =
|
|
660
|
+
let preload = `
|
|
661
|
+
${
|
|
662
|
+
path.trim().includes('.css') ? `<link rel="stylesheet" href="${path.trim()}">` : ''
|
|
663
|
+
}
|
|
664
|
+
${!path.trim().includes('.css') ? `<link rel="modulepreload" href="${path.trim()}">` : ''}<link rel="preload" href="${path.trim()}" as="${path.trim().includes('.css') ? 'style' : 'script'}">`
|
|
657
665
|
html = html.replace('</head>', `${preload}\n</head>`)
|
|
658
666
|
|
|
659
667
|
fs.writeFileSync(process.cwd() + '/dist/index.html', html)
|
|
@@ -882,10 +890,7 @@ async function Build() {
|
|
|
882
890
|
await writer(process.cwd() + "/dist/" + file, data);
|
|
883
891
|
});
|
|
884
892
|
|
|
885
|
-
}
|
|
886
|
-
let html = scannedFiles.filter((e) => e.includes('index.html'))[0]
|
|
887
|
-
console.log(html)
|
|
888
|
-
}
|
|
893
|
+
}
|
|
889
894
|
|
|
890
895
|
globalThis.isBuilding = false
|
|
891
896
|
console.log(`Build complete! ${Math.round(bundleSize / 1000)}${bundleSize > 1000 ? 'kb' : 'bytes'} written to ./dist`)
|