From 2e3fe07ed8426ca5db83005a8ddb886afb81b982 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 25 Jan 2018 12:04:27 -0500 Subject: [PATCH] fix: avoid dotfiles not being published to npm --- .../generator/template/{.gitignore => _gitignore} | 0 packages/@vue/cli/lib/GeneratorAPI.js | 11 +++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) rename packages/@vue/cli-service/generator/template/{.gitignore => _gitignore} (100%) diff --git a/packages/@vue/cli-service/generator/template/.gitignore b/packages/@vue/cli-service/generator/template/_gitignore similarity index 100% rename from packages/@vue/cli-service/generator/template/.gitignore rename to packages/@vue/cli-service/generator/template/_gitignore diff --git a/packages/@vue/cli/lib/GeneratorAPI.js b/packages/@vue/cli/lib/GeneratorAPI.js index 47688a7499..e53021edbc 100644 --- a/packages/@vue/cli/lib/GeneratorAPI.js +++ b/packages/@vue/cli/lib/GeneratorAPI.js @@ -62,11 +62,18 @@ module.exports = class GeneratorAPI { filter: file => path.basename(file.path) !== '.DS_Store' }) for (const file of _files) { - const relativePath = path.relative(fileDir, file.path) + let filename = path.basename(file.path) + // dotfiles are ignored when published to npm, therefore in templates + // we need to use underscore instead (e.g. "_gitignore") + if (filename.charAt(0) === '_') { + filename = `.${filename.slice(1)}` + } + const normalizedPath = path.join(path.dirname(file.path), filename) + const targetPath = path.relative(fileDir, normalizedPath) const content = renderFile(file.path, data, ejsOptions) // only set file if it's not all whitespace, or is a Buffer (binary files) if (Buffer.isBuffer(content) || /[^\s]/.test(content)) { - files[relativePath] = content + files[targetPath] = content } } })