]> git.ipfire.org Git - thirdparty/vuejs/create-vue.git/commitdiff
build: work around esbuild bundling issue on `import.meta.url`
authorHaoqun Jiang <haoqunjiang@gmail.com>
Fri, 17 Sep 2021 14:47:49 +0000 (22:47 +0800)
committerHaoqun Jiang <haoqunjiang@gmail.com>
Fri, 17 Sep 2021 14:48:36 +0000 (22:48 +0800)
.gitignore
index.js
package.json
snapshot.js

index a09092c4258ba5e8b29b473f3e6df5c10f406c31..5c1476158c180ac019c2ac214f2cb2b366f0c6d8 100644 (file)
@@ -1,4 +1,4 @@
-outfile.js
+outfile.cjs
 
 # Logs
 logs
index ab3eae75006febefa5df9b90a6c7033d6bb0e2b1..b05f0b343553c84734739915faf38de0b2999a61 100755 (executable)
--- a/index.js
+++ b/index.js
@@ -192,7 +192,11 @@ async function init() {
   const pkg = { name: packageName, version: '0.0.0' }
   fs.writeFileSync(path.resolve(root, 'package.json'), JSON.stringify(pkg, null, 2))
 
-  const templateRoot = new URL('./template', import.meta.url).pathname
+  // todo:
+  // work around the esbuild issue that `import.meta.url` cannot be correctly transpiled
+  // when bundling for node and the format is cjs
+  // const templateRoot = new URL('./template', import.meta.url).pathname
+  const templateRoot = path.resolve(__dirname, 'template')
   const render = function render(templateName) {
     const templateDir = path.resolve(templateRoot, templateName)
     renderTemplate(templateDir, root)
index 4f586c391aacd57de99de4072818863610f54542..06d72e9a3d5daabdc29c0dfdbdb63f77698e8681 100644 (file)
@@ -8,7 +8,7 @@
     "create-vue": "outfile.js"
   },
   "files": [
-    "outfile.js",
+    "outfile.cjs",
     "template"
   ],
   "engines": {
@@ -17,7 +17,7 @@
   "scripts": {
     "prepare": "husky install",
     "format": "prettier --write .",
-    "build": "esbuild --bundle index.js --format=esm --platform=node --outfile=outfile.js",
+    "build": "esbuild --bundle index.js --format=cjs --platform=node --outfile=outfile.cjs",
     "snapshot": "node snapshot.js",
     "pretest": "run-s build snapshot",
     "test": "node test.js",
index 3e41f98575b73578aa3293a652887c1d81b9d813..74232cbaeb020ee263b3c5cab466375224e3fe81 100644 (file)
@@ -1,6 +1,6 @@
 import { spawnSync } from 'child_process'
 
-const bin = new URL('./outfile.js', import.meta.url).pathname
+const bin = new URL('./outfile.cjs', import.meta.url).pathname
 const playgroundDir = new URL('./playground/', import.meta.url).pathname
 
 function createProjectWithFeatureFlags(flags) {