Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli-service): add envs dir config #3135

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ module.exports = {
`assetsDir` is ignored when overwriting the filename or chunkFilename from the generated assets.
:::

### environmentsDir

- Type: `string`
- Default: `''`

A directory where environment files will be loaded

### indexPath

- Type: `string`
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/mode-and-env.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Environment Variables and Modes

You can specify env variables by placing the following files in your project root:
You can specify env variables by placing the following files in your project root or customize it using `environmentsDir` option in `vue.config.js`:

``` bash
.env # loaded in all cases
Expand Down
12 changes: 7 additions & 5 deletions packages/@vue/cli-service/lib/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ module.exports = class Service {
this.initialized = true
this.mode = mode

// load user config
const userOptions = this.loadUserOptions()
this.projectOptions = defaultsDeep(userOptions, defaults())

// load mode .env
if (mode) {
this.loadEnv(mode)
}
// load base .env
this.loadEnv()

// load user config
const userOptions = this.loadUserOptions()
this.projectOptions = defaultsDeep(userOptions, defaults())

debug('vue:project-config')(this.projectOptions)

// apply plugins.
Expand All @@ -90,7 +90,9 @@ module.exports = class Service {

loadEnv (mode) {
const logger = debug('vue:env')
const basePath = path.resolve(this.context, `.env${mode ? `.${mode}` : ``}`)
const baseDir = this.projectOptions
? path.posix.join(this.context, this.projectOptions.environmentsDir) : this.context
const basePath = path.resolve(baseDir, `.env${mode ? `.${mode}` : ``}`)
const localPath = `${basePath}.local`

const load = path => {
Expand Down
4 changes: 4 additions & 0 deletions packages/@vue/cli-service/lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const schema = createSchema(joi => joi.object({
baseUrl: joi.string().allow(''),
outputDir: joi.string(),
assetsDir: joi.string().allow(''),
environmentsDir: joi.string().allow(''),
indexPath: joi.string(),
filenameHashing: joi.boolean(),
runtimeCompiler: joi.boolean(),
Expand Down Expand Up @@ -71,6 +72,9 @@ exports.defaults = () => ({
// where to put static assets (js/css/img/font/...)
assetsDir: '',

// where to load environments
environmentsDir: '',

// filename for index.html (relative to outputDir)
indexPath: 'index.html',

Expand Down
4 changes: 4 additions & 0 deletions packages/@vue/cli-ui/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,10 @@
"label": "Assets directory",
"description": "A directory to nest generated static assets (js, css, img, fonts) under."
},
"environmentsDir": {
"label": "Environments directory",
"description": "The directory where the environment files will be loaded"
},
"runtimeCompiler": {
"label": "Enable runtime compiler",
"description": "This will allow you to use the template option in Vue components, but will incur around an extra 10kb payload for your app."
Expand Down
10 changes: 10 additions & 0 deletions packages/@vue/cli-ui/ui-defaults/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ module.exports = api => {
group: 'org.vue.vue-webpack.config.vue-cli.groups.general',
link: 'https://cli.vuejs.org/config/#assetsdir'
},
{
name: 'environmentsDir',
type: 'input',
default: '',
value: data.vue && data.vue.environmentsDir,
message: 'org.vue.vue-webpack.config.vue-cli.environmentsDir.label',
description: 'org.vue.vue-webpack.config.vue-cli.environmentsDir.description',
group: 'org.vue.vue-webpack.config.vue-cli.groups.general',
link: 'https://cli.vuejs.org/config/#environmentsdir'
},
{
name: 'runtimeCompiler',
type: 'confirm',
Expand Down