mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-03-13 12:40:18 -05:00
chore: merge dev
This commit is contained in:
14
docs/css.md
14
docs/css.md
@@ -13,7 +13,15 @@ Vue CLI uses PostCSS internally, and enables [autoprefixer](https://github.com/p
|
||||
|
||||
You can [use CSS Modules in `*.vue` files](https://vue-loader.vuejs.org/en/features/css-modules.html) out of the box with `<style module>`.
|
||||
|
||||
If you wish to import style files as CSS Modules in JavaScript, you can import a file with a `?module` resourceQuery:
|
||||
To import CSS or other pre-processor files as CSS Modules in JavaScript, the filename should end with `.module.(css|less|sass|scss|styl)`:
|
||||
|
||||
``` js
|
||||
import styles from './foo.module.css'
|
||||
// works for all supported pre-processors as well
|
||||
import sassStyles from './foo.module.scss'
|
||||
```
|
||||
|
||||
Alternatively, you can import a file explicitly with a `?module` resourceQuery so that you can drop the `.module` in the filename:
|
||||
|
||||
``` js
|
||||
import styles from './foo.css?module'
|
||||
@@ -21,7 +29,7 @@ import styles from './foo.css?module'
|
||||
import sassStyles from './foo.scss?module'
|
||||
```
|
||||
|
||||
If you wish to customize the CSS modules class name output you can set the `css.localIdentName` option in `vue.config.js`.
|
||||
If you wish to customize the generated CSS modules class names, you can do so via the `css.localIdentName` option in `vue.config.js`.
|
||||
|
||||
### Pre-Processors
|
||||
|
||||
@@ -57,3 +65,5 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
This is preferred over manually tapping into specific loaders, because these options will be shared across all rules that are related to it.
|
||||
|
||||
@@ -51,11 +51,15 @@
|
||||
"jest": "^22.1.4",
|
||||
"lerna": "^2.8.0",
|
||||
"lint-staged": "^6.0.1",
|
||||
"memfs": "^2.6.0",
|
||||
"memfs": "^2.8.0",
|
||||
"puppeteer": "^1.0.0",
|
||||
"request": "^2.83.0",
|
||||
"request-promise-native": "^1.0.5",
|
||||
"rimraf": "^2.6.2",
|
||||
"yorkie": "^1.0.2"
|
||||
},
|
||||
"resolutions": {
|
||||
"fs-monkey": "0.3.1",
|
||||
"babel-core": "7.0.0-bridge.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
// hack babel's codegen to fix source map.
|
||||
// this is a temporary patch before the actual change is released.
|
||||
// TODO remove after upgrading Babel to 7.0.0-beta.47
|
||||
require('./patchBabel')
|
||||
|
||||
module.exports = (api, {
|
||||
parallel,
|
||||
transpileDependencies
|
||||
|
||||
398
packages/@vue/cli-plugin-babel/patchBabel.js
Normal file
398
packages/@vue/cli-plugin-babel/patchBabel.js
Normal file
@@ -0,0 +1,398 @@
|
||||
/* eslint-disable */
|
||||
|
||||
const mod = require('@babel/core/lib/transformation/file/generate')
|
||||
|
||||
function _convertSourceMap () {
|
||||
var data = _interopRequireDefault(require('convert-source-map'))
|
||||
|
||||
_convertSourceMap = function _convertSourceMap () {
|
||||
return data
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
function _generator () {
|
||||
var data = _interopRequireDefault(require('@babel/generator'))
|
||||
|
||||
_generator = function _generator () {
|
||||
return data
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
function _interopRequireDefault (obj) { return obj && obj.__esModule ? obj : { default: obj } }
|
||||
|
||||
mod.default = function generateCode (pluginPasses, file) {
|
||||
var opts = file.opts,
|
||||
ast = file.ast,
|
||||
shebang = file.shebang,
|
||||
code = file.code,
|
||||
inputMap = file.inputMap
|
||||
var results = []
|
||||
|
||||
for (var _iterator = pluginPasses, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator](); ;) {
|
||||
var _ref
|
||||
|
||||
if (_isArray) {
|
||||
if (_i >= _iterator.length) break
|
||||
_ref = _iterator[_i++]
|
||||
} else {
|
||||
_i = _iterator.next()
|
||||
if (_i.done) break
|
||||
_ref = _i.value
|
||||
}
|
||||
|
||||
var plugins = _ref
|
||||
|
||||
for (var _iterator2 = plugins, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator](); ;) {
|
||||
var _ref2
|
||||
|
||||
if (_isArray2) {
|
||||
if (_i2 >= _iterator2.length) break
|
||||
_ref2 = _iterator2[_i2++]
|
||||
} else {
|
||||
_i2 = _iterator2.next()
|
||||
if (_i2.done) break
|
||||
_ref2 = _i2.value
|
||||
}
|
||||
|
||||
var plugin = _ref2
|
||||
var generatorOverride = plugin.generatorOverride
|
||||
|
||||
if (generatorOverride) {
|
||||
var _result2 = generatorOverride(ast, opts.generatorOpts, code, _generator().default)
|
||||
|
||||
if (_result2 !== undefined) results.push(_result2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var result
|
||||
|
||||
if (results.length === 0) {
|
||||
result = (0, _generator().default)(ast, opts.generatorOpts, code)
|
||||
} else if (results.length === 1) {
|
||||
result = results[0]
|
||||
|
||||
if (typeof result.then === 'function') {
|
||||
throw new Error('You appear to be using an async parser plugin, ' + 'which your current version of Babel does not support. ' + "If you're using a published plugin, " + 'you may need to upgrade your @babel/core version.')
|
||||
}
|
||||
} else {
|
||||
throw new Error('More than one plugin attempted to override codegen.')
|
||||
}
|
||||
|
||||
var _result = result,
|
||||
outputCode = _result.code,
|
||||
outputMap = _result.map
|
||||
|
||||
if (shebang) {
|
||||
outputCode = shebang + '\n' + outputCode
|
||||
}
|
||||
|
||||
if (outputMap && inputMap) {
|
||||
outputMap = mergeSourceMap(inputMap.toObject(), outputMap)
|
||||
}
|
||||
|
||||
if (opts.sourceMaps === 'inline' || opts.sourceMaps === 'both') {
|
||||
outputCode += '\n' + _convertSourceMap().default.fromObject(outputMap).toComment()
|
||||
}
|
||||
|
||||
if (opts.sourceMaps === 'inline') {
|
||||
outputMap = null
|
||||
}
|
||||
|
||||
return {
|
||||
outputCode: outputCode,
|
||||
outputMap: outputMap
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
const sourceMap = require('source-map')
|
||||
|
||||
function mergeSourceMap (
|
||||
inputMap,
|
||||
map,
|
||||
) {
|
||||
const input = buildMappingData(inputMap)
|
||||
const output = buildMappingData(map)
|
||||
|
||||
// Babel-generated maps always map to a single input filename.
|
||||
if (output.sources.length !== 1) {
|
||||
throw new Error('Assertion failure - expected a single output file')
|
||||
}
|
||||
const defaultSource = output.sources[0]
|
||||
|
||||
const mergedGenerator = new sourceMap.SourceMapGenerator()
|
||||
for (const { source } of input.sources) {
|
||||
if (typeof source.content === 'string') {
|
||||
mergedGenerator.setSourceContent(source.path, source.content)
|
||||
}
|
||||
}
|
||||
|
||||
const insertedMappings = new Map()
|
||||
|
||||
// Process each generated range in the input map, e.g. each range over the
|
||||
// code that Babel was originally given.
|
||||
eachInputGeneratedRange(input, (generated, original, source) => {
|
||||
// Then pick out each range over Babel's _output_ that corresponds with
|
||||
// the given range on the code given to Babel.
|
||||
eachOverlappingGeneratedOutputRange(defaultSource, generated, item => {
|
||||
// It's possible that multiple input ranges will overlap the same
|
||||
// generated range. Since sourcemap don't traditionally represent
|
||||
// generated locations with multiple original locations, we explicitly
|
||||
// skip generated locations once we've seen them the first time.
|
||||
const key = makeMappingKey(item)
|
||||
if (insertedMappings.has(key)) return
|
||||
insertedMappings.set(key, item)
|
||||
|
||||
mergedGenerator.addMapping({
|
||||
source: source.path,
|
||||
original: {
|
||||
line: original.line,
|
||||
column: original.columnStart
|
||||
},
|
||||
generated: {
|
||||
line: item.line,
|
||||
column: item.columnStart
|
||||
},
|
||||
name: original.name
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
// Since mappings are manipulated using single locations, but are interpreted
|
||||
// as ranges, the insertions above may not actually have their ending
|
||||
// locations mapped yet. Here be go through each one and ensure that it has
|
||||
// a well-defined ending location, if one wasn't already created by the start
|
||||
// of a different range.
|
||||
for (const item of insertedMappings.values()) {
|
||||
if (item.columnEnd === Infinity) {
|
||||
continue
|
||||
}
|
||||
|
||||
const clearItem = {
|
||||
line: item.line,
|
||||
columnStart: item.columnEnd
|
||||
}
|
||||
|
||||
const key = makeMappingKey(clearItem)
|
||||
if (insertedMappings.has(key)) {
|
||||
continue
|
||||
}
|
||||
|
||||
// Insert mappings with no original position to terminate any mappings
|
||||
// that were found above, so that they don't expand beyond their correct
|
||||
// range.
|
||||
mergedGenerator.addMapping({
|
||||
generated: {
|
||||
line: clearItem.line,
|
||||
column: clearItem.columnStart
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const result = mergedGenerator.toJSON()
|
||||
// addMapping expects a relative path, and setSourceContent expects an
|
||||
// absolute path. To avoid this whole confusion, we leave the root out
|
||||
// entirely, and add it at the end here.
|
||||
if (typeof input.sourceRoot === 'string') {
|
||||
result.sourceRoot = input.sourceRoot
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
function makeMappingKey (item) {
|
||||
return JSON.stringify([item.line, item.columnStart])
|
||||
}
|
||||
|
||||
function eachOverlappingGeneratedOutputRange (
|
||||
outputFile,
|
||||
inputGeneratedRange,
|
||||
callback,
|
||||
) {
|
||||
// Find the Babel-generated mappings that overlap with this range in the
|
||||
// input sourcemap. Generated locations within the input sourcemap
|
||||
// correspond with the original locations in the map Babel generates.
|
||||
const overlappingOriginal = filterApplicableOriginalRanges(
|
||||
outputFile,
|
||||
inputGeneratedRange,
|
||||
)
|
||||
|
||||
for (const { generated } of overlappingOriginal) {
|
||||
for (const item of generated) {
|
||||
callback(item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function filterApplicableOriginalRanges (
|
||||
{ mappings },
|
||||
{ line, columnStart, columnEnd },
|
||||
) {
|
||||
// The mapping array is sorted by original location, so we can
|
||||
// binary-search it for the overlapping ranges.
|
||||
return filterSortedArray(mappings, ({ original: outOriginal }) => {
|
||||
if (line > outOriginal.line) return -1
|
||||
if (line < outOriginal.line) return 1
|
||||
|
||||
if (columnStart >= outOriginal.columnEnd) return -1
|
||||
if (columnEnd <= outOriginal.columnStart) return 1
|
||||
|
||||
return 0
|
||||
})
|
||||
}
|
||||
|
||||
function eachInputGeneratedRange (
|
||||
map,
|
||||
callback
|
||||
|
||||
,
|
||||
) {
|
||||
for (const { source, mappings } of map.sources) {
|
||||
for (const { original, generated } of mappings) {
|
||||
for (const item of generated) {
|
||||
callback(item, original, source)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function buildMappingData (map) {
|
||||
const consumer = new sourceMap.SourceMapConsumer({
|
||||
...map,
|
||||
|
||||
// This is a bit hack. .addMapping expects source values to be relative,
|
||||
// but eachMapping returns mappings with absolute paths. To avoid that
|
||||
// incompatibility, we leave the sourceRoot out here and add it to the
|
||||
// final map at the end instead.
|
||||
sourceRoot: null
|
||||
})
|
||||
|
||||
const sources = new Map()
|
||||
const mappings = new Map()
|
||||
|
||||
let last = null
|
||||
|
||||
consumer.computeColumnSpans()
|
||||
|
||||
consumer.eachMapping(
|
||||
m => {
|
||||
if (m.originalLine === null) return
|
||||
|
||||
let source = sources.get(m.source)
|
||||
if (!source) {
|
||||
source = {
|
||||
path: m.source,
|
||||
content: consumer.sourceContentFor(m.source, true)
|
||||
}
|
||||
sources.set(m.source, source)
|
||||
}
|
||||
|
||||
let sourceData = mappings.get(source)
|
||||
if (!sourceData) {
|
||||
sourceData = {
|
||||
source,
|
||||
mappings: []
|
||||
}
|
||||
mappings.set(source, sourceData)
|
||||
}
|
||||
|
||||
const obj = {
|
||||
line: m.originalLine,
|
||||
columnStart: m.originalColumn,
|
||||
columnEnd: Infinity,
|
||||
name: m.name
|
||||
}
|
||||
|
||||
if (
|
||||
last &&
|
||||
last.source === source &&
|
||||
last.mapping.line === m.originalLine
|
||||
) {
|
||||
last.mapping.columnEnd = m.originalColumn
|
||||
}
|
||||
|
||||
last = {
|
||||
source,
|
||||
mapping: obj
|
||||
}
|
||||
|
||||
sourceData.mappings.push({
|
||||
original: obj,
|
||||
generated: consumer
|
||||
.allGeneratedPositionsFor({
|
||||
source: m.source,
|
||||
line: m.originalLine,
|
||||
column: m.originalColumn
|
||||
})
|
||||
.map(item => ({
|
||||
line: item.line,
|
||||
columnStart: item.column,
|
||||
// source-map's lastColumn is inclusive, not exclusive, so we need
|
||||
// to add 1 to it.
|
||||
columnEnd: item.lastColumn + 1
|
||||
}))
|
||||
})
|
||||
},
|
||||
null,
|
||||
sourceMap.SourceMapConsumer.ORIGINAL_ORDER,
|
||||
)
|
||||
|
||||
return {
|
||||
file: map.file,
|
||||
sourceRoot: map.sourceRoot,
|
||||
sources: Array.from(mappings.values())
|
||||
}
|
||||
}
|
||||
|
||||
function findInsertionLocation (
|
||||
array,
|
||||
callback,
|
||||
) {
|
||||
let left = 0
|
||||
let right = array.length
|
||||
while (left < right) {
|
||||
const mid = Math.floor((left + right) / 2)
|
||||
const item = array[mid]
|
||||
|
||||
const result = callback(item)
|
||||
if (result === 0) {
|
||||
left = mid
|
||||
break
|
||||
}
|
||||
if (result >= 0) {
|
||||
right = mid
|
||||
} else {
|
||||
left = mid + 1
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure the value is the start of any set of matches.
|
||||
let i = left
|
||||
if (i < array.length) {
|
||||
while (i > 0 && callback(array[i]) >= 0) {
|
||||
i--
|
||||
}
|
||||
return i + 1
|
||||
}
|
||||
|
||||
return i
|
||||
}
|
||||
|
||||
function filterSortedArray (
|
||||
array,
|
||||
callback,
|
||||
) {
|
||||
const start = findInsertionLocation(array, callback)
|
||||
|
||||
const results = []
|
||||
for (let i = start; i < array.length && callback(array[i]) === 0; i++) {
|
||||
results.push(array[i])
|
||||
}
|
||||
|
||||
return results
|
||||
}
|
||||
@@ -26,6 +26,6 @@
|
||||
"deepmerge": "^2.1.0",
|
||||
"execa": "^0.10.0",
|
||||
"nightwatch": "^0.9.21",
|
||||
"selenium-server": "^3.11.0"
|
||||
"selenium-server": "^3.12.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
module.exports = (api, {
|
||||
classComponent,
|
||||
tsLint,
|
||||
lintOn = [],
|
||||
experimentalCompileTsWithBabel
|
||||
lintOn = []
|
||||
}) => {
|
||||
if (typeof lintOn === 'string') {
|
||||
lintOn = lintOn.split(',')
|
||||
@@ -17,35 +16,6 @@ module.exports = (api, {
|
||||
})
|
||||
}
|
||||
|
||||
if (experimentalCompileTsWithBabel) {
|
||||
api.extendPackage({
|
||||
devDependencies: {
|
||||
'@babel/preset-typescript': '7 || ^7.0.0-beta || ^7.0.0-rc'
|
||||
},
|
||||
vue: {
|
||||
experimentalCompileTsWithBabel: true
|
||||
},
|
||||
babel: {
|
||||
presets: ['@babel/typescript', '@vue/app']
|
||||
}
|
||||
})
|
||||
|
||||
if (classComponent) {
|
||||
api.extendPackage({
|
||||
devDependencies: {
|
||||
'@babel/plugin-proposal-decorators': '7 || ^7.0.0-beta || ^7.0.0-rc',
|
||||
'@babel/plugin-proposal-class-properties': '7 || ^7.0.0-beta || ^7.0.0-rc'
|
||||
},
|
||||
babel: {
|
||||
plugins: [
|
||||
'@babel/proposal-decorators',
|
||||
['@babel/proposal-class-properties', { 'loose': true }]
|
||||
]
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (tsLint) {
|
||||
api.extendPackage({
|
||||
scripts: {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
module.exports = (api, {
|
||||
parallel,
|
||||
lintOnSave,
|
||||
experimentalCompileTsWithBabel
|
||||
lintOnSave
|
||||
}) => {
|
||||
const fs = require('fs')
|
||||
const useThreads = process.env.NODE_ENV === 'production' && parallel
|
||||
@@ -35,35 +34,26 @@ module.exports = (api, {
|
||||
})
|
||||
}
|
||||
|
||||
if (!experimentalCompileTsWithBabel) {
|
||||
if (api.hasPlugin('babel')) {
|
||||
addLoader({
|
||||
loader: 'babel-loader'
|
||||
})
|
||||
}
|
||||
addLoader({
|
||||
loader: 'ts-loader',
|
||||
options: {
|
||||
transpileOnly: true,
|
||||
appendTsSuffixTo: [/\.vue$/],
|
||||
// https://github.com/TypeStrong/ts-loader#happypackmode-boolean-defaultfalse
|
||||
happyPackMode: useThreads
|
||||
}
|
||||
})
|
||||
// make sure to append TSX suffix
|
||||
tsxRule.use('ts-loader').loader('ts-loader').tap(options => {
|
||||
delete options.appendTsSuffixTo
|
||||
options.appendTsxSuffixTo = [/\.vue$/]
|
||||
return options
|
||||
})
|
||||
} else {
|
||||
// Experimental: compile TS with babel so that it can leverage
|
||||
// preset-env for auto-detected polyfills based on browserslists config.
|
||||
// this is pending on the readiness of @babel/preset-typescript.
|
||||
if (api.hasPlugin('babel')) {
|
||||
addLoader({
|
||||
loader: 'babel-loader'
|
||||
})
|
||||
}
|
||||
addLoader({
|
||||
loader: 'ts-loader',
|
||||
options: {
|
||||
transpileOnly: true,
|
||||
appendTsSuffixTo: [/\.vue$/],
|
||||
// https://github.com/TypeStrong/ts-loader#happypackmode-boolean-defaultfalse
|
||||
happyPackMode: useThreads
|
||||
}
|
||||
})
|
||||
// make sure to append TSX suffix
|
||||
tsxRule.use('ts-loader').loader('ts-loader').tap(options => {
|
||||
delete options.appendTsSuffixTo
|
||||
options.appendTsxSuffixTo = [/\.vue$/]
|
||||
return options
|
||||
})
|
||||
|
||||
config
|
||||
.plugin('fork-ts-checker')
|
||||
|
||||
@@ -10,11 +10,7 @@ module.exports = [
|
||||
type: `confirm`,
|
||||
message: `Use class-style component syntax?`
|
||||
},
|
||||
process.env.VUE_CLI_EXPERIMENTAL ? {
|
||||
name: `experimentalCompileTsWithBabel`,
|
||||
type: `confirm`,
|
||||
message: `Compile TS with babel? ${chalk.yellow(`(experimental)`)}`
|
||||
} : {
|
||||
{
|
||||
name: `useTsWithBabel`,
|
||||
type: `confirm`,
|
||||
message: `Use Babel alongside TypeScript for auto-detected polyfills?`
|
||||
|
||||
@@ -39,9 +39,9 @@ module.exports = api => {
|
||||
jestConfig.transform['^.+\\.jsx?$'] = 'babel-jest'
|
||||
api.extendPackage({
|
||||
devDependencies: {
|
||||
'babel-jest': '^22.0.4',
|
||||
'babel-jest': '^22.4.3',
|
||||
// this is for now necessary to force babel-jest and vue-jest to use babel 7
|
||||
'babel-core': '^7.0.0-0'
|
||||
'babel-core': '7.0.0-bridge.0'
|
||||
}
|
||||
})
|
||||
} else {
|
||||
@@ -49,14 +49,14 @@ module.exports = api => {
|
||||
jestConfig.transform['^.+\\.tsx?$'] = 'ts-jest'
|
||||
api.extendPackage({
|
||||
devDependencies: {
|
||||
'ts-jest': '^22.0.1'
|
||||
'ts-jest': '^22.4.6'
|
||||
}
|
||||
})
|
||||
if (api.hasPlugin('babel')) {
|
||||
api.extendPackage({
|
||||
devDependencies: {
|
||||
// this is for now necessary to force ts-jest and vue-jest to use babel 7
|
||||
'babel-core': '^7.0.0-0'
|
||||
'babel-core': '7.0.0-bridge.0'
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vue/test-utils": "^1.0.0-beta.16",
|
||||
"babel-jest": "^22.0.4",
|
||||
"ts-jest": "^22.0.1"
|
||||
"babel-jest": "^22.4.3",
|
||||
"ts-jest": "^22.4.6"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ const genConfig = (pkg = {}, env) => {
|
||||
return config
|
||||
}
|
||||
|
||||
const findRule = (config, lang, index = 1) => {
|
||||
const findRule = (config, lang, index = 2) => {
|
||||
const baseRule = config.module.rules.find(rule => {
|
||||
return rule.test.test(`.${lang}`)
|
||||
})
|
||||
@@ -55,7 +55,7 @@ test('default loaders', () => {
|
||||
expect(findOptions(config, lang, 'css')).toEqual({
|
||||
minimize: false,
|
||||
sourceMap: false,
|
||||
importLoaders: lang === 'css' ? 1 : 2
|
||||
importLoaders: lang === 'css' ? 2 : 3
|
||||
})
|
||||
})
|
||||
// sass indented syntax
|
||||
@@ -70,7 +70,7 @@ test('production defaults', () => {
|
||||
expect(findOptions(config, lang, 'css')).toEqual({
|
||||
minimize: true,
|
||||
sourceMap: false,
|
||||
importLoaders: lang === 'css' ? 1 : 2
|
||||
importLoaders: lang === 'css' ? 2 : 3
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -78,13 +78,17 @@ test('production defaults', () => {
|
||||
test('CSS Modules rules', () => {
|
||||
const config = genConfig()
|
||||
LANGS.forEach(lang => {
|
||||
expect(findOptions(config, lang, 'css', 0)).toEqual({
|
||||
importLoaders: lang === 'css' ? 0 : 1, // no postcss-loader
|
||||
const expected = {
|
||||
importLoaders: lang === 'css' ? 1 : 2, // no postcss-loader
|
||||
localIdentName: `[name]_[local]_[hash:base64:5]`,
|
||||
minimize: false,
|
||||
sourceMap: false,
|
||||
modules: true
|
||||
})
|
||||
}
|
||||
// module-query rules
|
||||
expect(findOptions(config, lang, 'css', 0)).toEqual(expected)
|
||||
// module-ext rules
|
||||
expect(findOptions(config, lang, 'css', 1)).toEqual(expected)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ module.exports = (api, options) => {
|
||||
'vue': '^2.5.16'
|
||||
},
|
||||
devDependencies: {
|
||||
'vue-template-compiler': '^2.5.13'
|
||||
'vue-template-compiler': '^2.5.16'
|
||||
},
|
||||
'postcss': {
|
||||
'plugins': {
|
||||
@@ -43,16 +43,16 @@ module.exports = (api, options) => {
|
||||
if (options.cssPreprocessor) {
|
||||
const deps = {
|
||||
sass: {
|
||||
'node-sass': '^4.7.2',
|
||||
'sass-loader': '^6.0.6'
|
||||
'node-sass': '^4.9.0',
|
||||
'sass-loader': '^7.0.1'
|
||||
},
|
||||
less: {
|
||||
'less': '^2.7.3',
|
||||
'less-loader': '^4.0.5'
|
||||
'less': '^3.0.4',
|
||||
'less-loader': '^4.1.0'
|
||||
},
|
||||
stylus: {
|
||||
'stylus': '^0.54.5',
|
||||
'stylus-loader': '^3.0.1'
|
||||
'stylus-loader': '^3.0.2'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,6 +83,10 @@ module.exports = (api, options) => {
|
||||
usage: 'vue-cli-service inspect [options] [...paths]',
|
||||
options: {
|
||||
'--mode': 'specify env mode (default: development)',
|
||||
'--rule <ruleName>': 'inspect a specific module rule',
|
||||
'--plugin <pluginName>': 'inspect a specific plugin',
|
||||
'--rules': 'list all module rule names',
|
||||
'--plugins': 'list all plugin names',
|
||||
'--verbose': 'show full function definitions in output'
|
||||
}
|
||||
}, args => {
|
||||
@@ -94,7 +98,15 @@ module.exports = (api, options) => {
|
||||
const paths = args._
|
||||
|
||||
let res
|
||||
if (paths.length > 1) {
|
||||
if (args.rule) {
|
||||
res = config.module.rules.find(r => r.__ruleName === args.rule)
|
||||
} else if (args.plugin) {
|
||||
res = config.plugins.find(p => p.__pluginName === args.plugin)
|
||||
} else if (args.rules) {
|
||||
res = config.module.rules.map(r => r.__ruleName)
|
||||
} else if (args.plugins) {
|
||||
res = config.plugins.map(p => p.__pluginName)
|
||||
} else if (paths.length > 1) {
|
||||
res = {}
|
||||
paths.forEach(path => {
|
||||
res[path] = get(config, path)
|
||||
@@ -106,7 +118,7 @@ module.exports = (api, options) => {
|
||||
}
|
||||
|
||||
const pluginRE = /(?:function|class) (\w+Plugin)/
|
||||
console.log(stringify(res, (value, indent, stringify) => {
|
||||
const output = stringify(res, (value, indent, stringify) => {
|
||||
// shorten long functions
|
||||
if (
|
||||
!args.verbose &&
|
||||
@@ -151,7 +163,9 @@ module.exports = (api, options) => {
|
||||
}
|
||||
|
||||
return stringify(value)
|
||||
}, 2))
|
||||
}, 2)
|
||||
|
||||
console.log(output)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -41,9 +41,13 @@ module.exports = (api, options) => {
|
||||
const baseRule = webpackConfig.module.rule(lang).test(test)
|
||||
|
||||
// rules for <style lang="module">
|
||||
const modulesRule = baseRule.oneOf('modules').resourceQuery(/module/)
|
||||
const modulesRule = baseRule.oneOf('modules-query').resourceQuery(/module/)
|
||||
applyLoaders(modulesRule, true)
|
||||
|
||||
// rules for *.module.* files
|
||||
const modulesExtRule = baseRule.oneOf('modules-ext').test(/\.module\.\w+$/)
|
||||
applyLoaders(modulesExtRule, true)
|
||||
|
||||
const normalRule = baseRule.oneOf('normal')
|
||||
applyLoaders(normalRule, false)
|
||||
|
||||
@@ -65,7 +69,11 @@ module.exports = (api, options) => {
|
||||
const cssLoaderOptions = {
|
||||
minimize: isProd,
|
||||
sourceMap,
|
||||
importLoaders: hasPostCSSConfig + !!loader // boolean + boolean
|
||||
importLoaders: (
|
||||
1 + // stylePostLoader injected by vue-loader
|
||||
hasPostCSSConfig +
|
||||
!!loader
|
||||
)
|
||||
}
|
||||
if (modules) {
|
||||
Object.assign(cssLoaderOptions, {
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
"escape-string-regexp": "^1.0.5",
|
||||
"file-loader": "^1.1.11",
|
||||
"friendly-errors-webpack-plugin": "^1.7.0",
|
||||
"fs-extra": "^6.0.0",
|
||||
"fs-extra": "^6.0.1",
|
||||
"get-value": "^3.0.1",
|
||||
"globby": "^8.0.1",
|
||||
"html-webpack-plugin": "^3.2.0",
|
||||
@@ -62,7 +62,7 @@
|
||||
"url-loader": "^1.0.1",
|
||||
"vue-loader": "^15.0.10",
|
||||
"vue-template-compiler": "^2.5.16",
|
||||
"webpack": "^4.8.1",
|
||||
"webpack": "^4.8.2",
|
||||
"webpack-chain": "^4.6.0",
|
||||
"webpack-dev-server": "^3.1.4",
|
||||
"webpack-merge": "^4.1.2",
|
||||
|
||||
@@ -68,6 +68,10 @@ program
|
||||
program
|
||||
.command('inspect [paths...]')
|
||||
.option('--mode <mode>')
|
||||
.option('--rule <ruleName>', 'inspect a specific module rule')
|
||||
.option('--plugin <pluginName>', 'inspect a specific plugin')
|
||||
.option('--rules', 'list all module rule names')
|
||||
.option('--plugins', 'list all plugin names')
|
||||
.option('-v --verbose', 'Show full function definitions in output')
|
||||
.description('inspect the webpack config in a project with vue-cli-service')
|
||||
.action((paths, cmd) => {
|
||||
|
||||
@@ -333,7 +333,7 @@ module.exports = class Creator extends EventEmitter {
|
||||
type: 'checkbox',
|
||||
message: 'Check the features needed for your project:',
|
||||
choices: [],
|
||||
pageSize: 8
|
||||
pageSize: 10
|
||||
}
|
||||
return {
|
||||
presetPrompt,
|
||||
|
||||
@@ -19,6 +19,10 @@ module.exports = function inspect (paths, args) {
|
||||
binPath,
|
||||
'inspect',
|
||||
...(args.mode ? ['--mode', args.mode] : []),
|
||||
...(args.rule ? ['--rule', args.rule] : []),
|
||||
...(args.plugin ? ['--plugin', args.plugin] : []),
|
||||
...(args.rules ? ['--rules'] : []),
|
||||
...(args.plugins ? ['--plugins'] : []),
|
||||
...(args.verbose ? ['--verbose'] : []),
|
||||
...paths
|
||||
], { cwd, stdio: 'inherit' })
|
||||
|
||||
@@ -9,7 +9,7 @@ test('should pass', async () => {
|
||||
const expectedPrompts = [
|
||||
{
|
||||
message: 'features',
|
||||
check: []
|
||||
check: [0]
|
||||
}
|
||||
]
|
||||
|
||||
@@ -27,7 +27,36 @@ test('should pass', async () => {
|
||||
)
|
||||
})
|
||||
|
||||
test('should not include the plugin if ts is also present', async () => {
|
||||
test('with TS', async () => {
|
||||
const mockTSModule = api => {
|
||||
api.onPromptComplete(answers => {
|
||||
answers.useTsWithBabel = true
|
||||
answers.features.push('ts')
|
||||
})
|
||||
}
|
||||
|
||||
const expectedPrompts = [
|
||||
{
|
||||
message: 'features',
|
||||
check: [] // no need to check if "useTsWithBabel" is explicitly true
|
||||
}
|
||||
]
|
||||
|
||||
const expectedOptions = {
|
||||
plugins: {
|
||||
'@vue/cli-plugin-babel': {}
|
||||
}
|
||||
}
|
||||
|
||||
await assertPromptModule(
|
||||
[mockTSModule, moduleToTest],
|
||||
expectedPrompts,
|
||||
expectedOptions,
|
||||
{ pluginsOnly: true }
|
||||
)
|
||||
})
|
||||
|
||||
test('with TS, no Babel', async () => {
|
||||
const mockTSModule = api => {
|
||||
api.onPromptComplete(answers => {
|
||||
answers.features.push('ts')
|
||||
|
||||
@@ -1,11 +1,21 @@
|
||||
module.exports = cli => {
|
||||
cli.injectFeature({
|
||||
name: 'Babel',
|
||||
value: 'babel',
|
||||
short: 'Babel',
|
||||
checked: true
|
||||
})
|
||||
|
||||
cli.onPromptComplete((answers, options) => {
|
||||
if (
|
||||
!answers.features.includes('ts') ||
|
||||
answers.useTsWithBabel ||
|
||||
answers.experimentalCompileTsWithBabel
|
||||
) {
|
||||
options.plugins['@vue/cli-plugin-babel'] = {}
|
||||
if (answers.features.includes('ts')) {
|
||||
if (!answers.useTsWithBabel) {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if (!answers.features.includes('babel')) {
|
||||
return
|
||||
}
|
||||
}
|
||||
options.plugins['@vue/cli-plugin-babel'] = {}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@ module.exports = cli => {
|
||||
short: 'Linter',
|
||||
description: 'Check and enforce code quality with ESLint or Prettier',
|
||||
link: 'https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint',
|
||||
plugins: ['eslint']
|
||||
plugins: ['eslint'],
|
||||
checked: true
|
||||
})
|
||||
|
||||
cli.injectPrompt({
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
const chalk = require('chalk')
|
||||
|
||||
module.exports = cli => {
|
||||
cli.injectFeature({
|
||||
name: 'TypeScript',
|
||||
@@ -17,21 +15,13 @@ module.exports = cli => {
|
||||
message: 'Use class-style component syntax?'
|
||||
})
|
||||
|
||||
if (process.env.VUE_CLI_EXPERIMENTAL) {
|
||||
cli.injectPrompt({
|
||||
name: 'compileTsWithBabel',
|
||||
when: answers => answers.features.includes('ts'),
|
||||
type: 'confirm',
|
||||
message: `Compile TS with babel? ${chalk.yellow(`(experimental)`)}`
|
||||
})
|
||||
} else {
|
||||
cli.injectPrompt({
|
||||
name: 'useTsWithBabel',
|
||||
when: answers => answers.features.includes('ts'),
|
||||
type: 'confirm',
|
||||
message: 'Use Babel alongside TypeScript for auto-detected polyfills?'
|
||||
})
|
||||
}
|
||||
cli.injectPrompt({
|
||||
name: 'useTsWithBabel',
|
||||
when: answers => answers.features.includes('ts'),
|
||||
type: 'confirm',
|
||||
message: 'Use Babel alongside TypeScript for auto-detected polyfills?',
|
||||
default: answers => answers.features.includes('babel')
|
||||
})
|
||||
|
||||
cli.onPromptComplete((answers, options) => {
|
||||
if (answers.features.includes('ts')) {
|
||||
@@ -44,8 +34,6 @@ module.exports = cli => {
|
||||
}
|
||||
if (answers.useTsWithBabel) {
|
||||
tsOptions.useTsWithBabel = true
|
||||
} else if (answers.compileTsWithBabel) {
|
||||
tsOptions.experimentalCompileTsWithBabel = true
|
||||
}
|
||||
options.plugins['@vue/cli-plugin-typescript'] = tsOptions
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user