vaderjs 1.3.3-alpha-82 → 1.3.3-alpha-84

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 (2) hide show
  1. package/package.json +1 -1
  2. package/vader.js +48 -45
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "vaderjs",
3
3
  "description": "A Reactive library aimed to helping you build reactive applications inspired by react.js",
4
4
  "module": "vader.js",
5
- "version": "1.3.3-alpha-82",
5
+ "version": "1.3.3-alpha-84",
6
6
  "bin": {
7
7
  "vader": "./vader.js"
8
8
  },
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,53 @@ function Compiler(func, file) {
612
614
  let newImport = ''
613
615
  let name = match.split('import')[1].split('from')[0].trim()
614
616
 
615
- if (path && path.includes('json')) {
616
- path = path.replace(';', '')
617
- newImport = `let ${name} = await fetch('${path}').then(res => res.json())`
618
- } else if (path && path.includes('module.css')) {
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
- string = string.replace(beforePath, "'" + path + "'")
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
+ path = path.replaceAll('.jsx', '.js');
648
+
649
+
650
+ string = string.replace(beforePath, "'" + path + "'")
651
+ break;
652
+
651
653
  }
654
+
652
655
  let html = fs.existsSync(process.cwd() + '/dist/index.html') ? fs.readFileSync(process.cwd() + '/dist/index.html', 'utf8') : ''
653
656
  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')
657
+ && !path.includes('.module.css')
655
658
  ) {
656
- let preload = `${!path.trim().includes('.css') ? `<link rel="modulepreload" href="${path.trim()}">` : ''}<link rel="preload" href="${path.trim()}" as="${path.trim().includes('.css') ? 'style' : 'script'}">`
659
+ let preload = `
660
+ ${
661
+ path.trim().includes('.css') ? `<link rel="stylesheet" href="${path.trim()}">` : ''
662
+ }
663
+ ${!path.trim().includes('.css') ? `<link rel="modulepreload" href="${path.trim()}">` : ''}<link rel="preload" href="${path.trim()}" as="${path.trim().includes('.css') ? 'style' : 'script'}">`
657
664
  html = html.replace('</head>', `${preload}\n</head>`)
658
665
 
659
666
  fs.writeFileSync(process.cwd() + '/dist/index.html', html)
@@ -866,8 +873,7 @@ async function Build() {
866
873
 
867
874
  scannedFiles.forEach(async (file) => {
868
875
  file = file.split(process.cwd() + '/runtime/')[1]
869
-
870
- console.log(file)
876
+
871
877
  let objCase = {
872
878
  ...file == "app.js" ? { exit: true } : null,
873
879
  ...file.includes("index.html") && fs.existsSync(process.cwd() + "/runtime/" + file) ? { exit: true } : null,
@@ -882,10 +888,7 @@ async function Build() {
882
888
  await writer(process.cwd() + "/dist/" + file, data);
883
889
  });
884
890
 
885
- }else if(process.env.isCloudflare){
886
- let htmlFile = fs.readFileSync(process.cwd() + "/node_modules/vaderjs/runtime/index.html", 'utf8')
887
- fs.writeFileSync(process.cwd() + "/dist/index.html", htmlFile)
888
- }
891
+ }
889
892
 
890
893
  globalThis.isBuilding = false
891
894
  console.log(`Build complete! ${Math.round(bundleSize / 1000)}${bundleSize > 1000 ? 'kb' : 'bytes'} written to ./dist`)