Skip to content

Commit a9aa3de

Browse files
LinusBorgAkryum
authored andcommitted
fix: underscore escaping for dotfiles (vuejs#1737)
* WIP: fix undersocre escaping for dotfiles (fix vuejs#1732) * Fix charAt * adding a short explanation to the docs. * improved wording
1 parent 286d75e commit a9aa3de

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

docs/dev-guide/plugin-dev.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,30 @@ export default {
235235
<%# END_REPLACE %>
236236
```
237237

238+
#### Filename edge cases
239+
240+
If you want to render a template file that either begins with a dot (i.e. `.env`) you will have to follow a specific naming convention, since dotfiles are ignored when publishing your plugin to npm:
241+
```
242+
# dotfile templates have to use an underscore instead of the dot:
243+
244+
/generator/template/_env
245+
246+
# When calling api.render('./template'), this will be rendered in the project folder as:
247+
248+
.env
249+
```
250+
Consequently, this means that you also have to follow a special naming convention if you want to render file whose name actually begins with an underscore:
251+
```
252+
# such templates have to use two underscores instead of the dot:
253+
254+
/generator/template/__variables.scss
255+
256+
# When calling api.render('./template'), this will be rendered in the project folder as:
257+
258+
_variables.scss
259+
```
260+
261+
238262
### Prompts
239263

240264
#### Prompts for Built-in Plugins

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,12 @@ class GeneratorAPI {
138138
let filename = path.basename(rawPath)
139139
// dotfiles are ignored when published to npm, therefore in templates
140140
// we need to use underscore instead (e.g. "_gitignore")
141-
if (filename.charAt(0) === '_') {
141+
if (filename.charAt(0) === '_' && filename.charAt(1) !== '_') {
142142
filename = `.${filename.slice(1)}`
143143
}
144+
if (filename.charAt(0) === '_' && filename.charAt(1) === '_') {
145+
filename = `${filename.slice(1)}`
146+
}
144147
const targetPath = path.join(path.dirname(rawPath), filename)
145148
const sourcePath = path.resolve(source, rawPath)
146149
const content = renderFile(sourcePath, data, ejsOptions)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy