mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-01-28 10:09:18 -06:00
revert: feat: load config w/ cosmiconfig
This reverts commit 52881223c3.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
jest.mock('fs')
|
||||
jest.mock('mock-config', () => ({ lintOnSave: false }), { virtual: true })
|
||||
jest.mock('vue-cli-plugin-foo', () => () => {}, { virtual: true })
|
||||
|
||||
const fs = require('fs')
|
||||
@@ -52,24 +53,16 @@ test('load project options from package.json', () => {
|
||||
})
|
||||
|
||||
test('load project options from vue.config.js', () => {
|
||||
fs.writeFileSync('/vue.config.js', `module.exports=${JSON.stringify({ lintOnSave: false })}`)
|
||||
const service = createMockService()
|
||||
// vue.config.js has higher priority
|
||||
expect(service.projectOptions.lintOnSave).toBe(false)
|
||||
fs.unlinkSync('/vue.config.js')
|
||||
})
|
||||
|
||||
test('package.json option should take priority', () => {
|
||||
fs.writeFileSync('/vue.config.js', `module.exports=${JSON.stringify({ lintOnSave: false })}`)
|
||||
process.env.VUE_CLI_SERVICE_CONFIG_PATH = 'mock-config'
|
||||
mockPkg({
|
||||
vue: {
|
||||
lintOnSave: true
|
||||
}
|
||||
})
|
||||
const service = createMockService()
|
||||
// package.json has higher priority
|
||||
expect(service.projectOptions.lintOnSave).toBe(true)
|
||||
fs.unlinkSync('/vue.config.js')
|
||||
// vue.config.js has higher priority
|
||||
expect(service.projectOptions.lintOnSave).toBe(false)
|
||||
delete process.env.VUE_CLI_SERVICE_CONFIG_PATH
|
||||
})
|
||||
|
||||
test('api: setMode', () => {
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const debug = require('debug')
|
||||
const chalk = require('chalk')
|
||||
const readPkg = require('read-pkg')
|
||||
const merge = require('webpack-merge')
|
||||
const deepMerge = require('deepmerge')
|
||||
const Config = require('webpack-chain')
|
||||
const PluginAPI = require('./PluginAPI')
|
||||
const loadEnv = require('./util/loadEnv')
|
||||
const cosmiconfig = require('cosmiconfig')
|
||||
const { error } = require('@vue/cli-shared-utils')
|
||||
const { warn, error } = require('@vue/cli-shared-utils')
|
||||
|
||||
const { defaults, validate } = require('./options')
|
||||
|
||||
@@ -155,25 +155,45 @@ module.exports = class Service {
|
||||
}
|
||||
|
||||
loadProjectOptions (inlineOptions) {
|
||||
let resolved
|
||||
if (this.pkg.vue) {
|
||||
resolved = this.pkg.vue
|
||||
} else {
|
||||
const explorer = cosmiconfig('vue', {
|
||||
rc: false,
|
||||
sync: true,
|
||||
stopDir: this.context
|
||||
})
|
||||
try {
|
||||
const res = explorer.load(this.context)
|
||||
if (res) resolved = res.config
|
||||
} catch (e) {
|
||||
// vue.config.js
|
||||
let fileConfig, pkgConfig, resolved
|
||||
const configPath = (
|
||||
process.env.VUE_CLI_SERVICE_CONFIG_PATH ||
|
||||
path.resolve(this.context, 'vue.config.js')
|
||||
)
|
||||
try {
|
||||
fileConfig = require(configPath)
|
||||
if (!fileConfig || typeof fileConfig !== 'object') {
|
||||
error(
|
||||
`Error loading vue-cli config: ${e.message}`
|
||||
`Error loading ${chalk.bold('vue.config.js')}: should export an object.`
|
||||
)
|
||||
fileConfig = null
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
// package.vue
|
||||
pkgConfig = this.pkg.vue
|
||||
if (pkgConfig && typeof pkgConfig !== 'object') {
|
||||
error(
|
||||
`Error loading vue-cli config in ${chalk.bold(`package.json`)}: ` +
|
||||
`the "vue" field should be an object.`
|
||||
)
|
||||
pkgConfig = null
|
||||
}
|
||||
|
||||
if (fileConfig) {
|
||||
if (pkgConfig) {
|
||||
warn(
|
||||
`"vue" field in ${chalk.bold(`package.json`)} ignored ` +
|
||||
`due to presence of ${chalk.bold('vue.config.js')}.`
|
||||
)
|
||||
}
|
||||
resolved = fileConfig
|
||||
} else if (pkgConfig) {
|
||||
resolved = pkgConfig
|
||||
} else {
|
||||
resolved = inlineOptions || {}
|
||||
}
|
||||
resolved = resolved || inlineOptions || {}
|
||||
|
||||
// normlaize some options
|
||||
ensureSlash(resolved, 'base')
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
"case-sensitive-paths-webpack-plugin": "^2.1.1",
|
||||
"chalk": "^2.3.0",
|
||||
"copy-webpack-plugin": "^4.3.1",
|
||||
"cosmiconfig": "^4.0.0",
|
||||
"css-loader": "^0.28.9",
|
||||
"deepmerge": "^2.0.1",
|
||||
"escape-string-regexp": "^1.0.5",
|
||||
|
||||
Reference in New Issue
Block a user