Skip to content

Commit 2e3fe07

Browse files
committed
fix: avoid dotfiles not being published to npm
1 parent b913047 commit 2e3fe07

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

packages/@vue/cli/lib/GeneratorAPI.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,18 @@ module.exports = class GeneratorAPI {
6262
filter: file => path.basename(file.path) !== '.DS_Store'
6363
})
6464
for (const file of _files) {
65-
const relativePath = path.relative(fileDir, file.path)
65+
let filename = path.basename(file.path)
66+
// dotfiles are ignored when published to npm, therefore in templates
67+
// we need to use underscore instead (e.g. "_gitignore")
68+
if (filename.charAt(0) === '_') {
69+
filename = `.${filename.slice(1)}`
70+
}
71+
const normalizedPath = path.join(path.dirname(file.path), filename)
72+
const targetPath = path.relative(fileDir, normalizedPath)
6673
const content = renderFile(file.path, data, ejsOptions)
6774
// only set file if it's not all whitespace, or is a Buffer (binary files)
6875
if (Buffer.isBuffer(content) || /[^\s]/.test(content)) {
69-
files[relativePath] = content
76+
files[targetPath] = content
7077
}
7178
}
7279
})

0 commit comments

Comments
 (0)