From: Haoqun Jiang Date: Fri, 17 Sep 2021 14:47:49 +0000 (+0800) Subject: build: work around esbuild bundling issue on `import.meta.url` X-Git-Tag: v3.0.0-beta.2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a4a832fc7dce5e6ad89737bd7f914903a8525606;p=thirdparty%2Fvuejs%2Fcreate-vue.git build: work around esbuild bundling issue on `import.meta.url` --- diff --git a/.gitignore b/.gitignore index a09092c4..5c147615 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -outfile.js +outfile.cjs # Logs logs diff --git a/index.js b/index.js index ab3eae75..b05f0b34 100755 --- 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) diff --git a/package.json b/package.json index 4f586c39..06d72e9a 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/snapshot.js b/snapshot.js index 3e41f985..74232cba 100644 --- a/snapshot.js +++ b/snapshot.js @@ -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) {