mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-04-22 12:28:44 -05:00
babel preset
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
# @vue/babel-preset-app
|
||||
|
||||
> babel-preset-app for vue-cli
|
||||
@@ -0,0 +1,52 @@
|
||||
const path = require('path')
|
||||
|
||||
module.exports = (context, options = {}) => {
|
||||
const presets = []
|
||||
const plugins = []
|
||||
|
||||
// JSX
|
||||
if (options.jsx !== false) {
|
||||
plugins.push(
|
||||
require('@babel/plugin-syntax-jsx').default,
|
||||
require('babel-plugin-transform-vue-jsx'),
|
||||
require('babel-plugin-jsx-event-modifiers'),
|
||||
require('babel-plugin-jsx-v-model')
|
||||
)
|
||||
}
|
||||
|
||||
const envOptions = {
|
||||
modules: options.modules || false,
|
||||
useBuiltIns: 'usage',
|
||||
targets: options.targets
|
||||
}
|
||||
delete envOptions.jsx
|
||||
// target running node version (this is set by unit testing plugins)
|
||||
if (process.env.VUE_CLI_BABEL_TARGET_NODE) {
|
||||
envOptions.targets = { node: 'current' }
|
||||
}
|
||||
// cli-plugin-jest sets this to true because Jest runs without bundling
|
||||
if (process.env.VUE_CLI_BABEL_TRANSPILE_MODULES) {
|
||||
envOptions.mdoules = true
|
||||
}
|
||||
|
||||
// pass options along to babel-preset-env
|
||||
presets.push([require('@babel/preset-env').default, envOptions])
|
||||
|
||||
// stage 2. This includes some important transforms, e.g. dynamic import
|
||||
// and rest object spread.
|
||||
presets.push([require('@babel/preset-stage-2').default, {
|
||||
useBuiltIns: true
|
||||
}])
|
||||
|
||||
// transform runtime, but only for helpers
|
||||
plugins.push([require('@babel/plugin-transform-runtime'), {
|
||||
polyfill: false,
|
||||
regenerator: false,
|
||||
moduleName: path.dirname(require.resolve('@babel/runtime/package.json'))
|
||||
}])
|
||||
|
||||
return {
|
||||
presets,
|
||||
plugins
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "@vue/babel-preset-app",
|
||||
"version": "0.1.0",
|
||||
"description": "babel-preset-app for vue-cli",
|
||||
"main": "index.js",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/vuejs/vue-cli.git"
|
||||
},
|
||||
"keywords": [
|
||||
"vue",
|
||||
"cli"
|
||||
],
|
||||
"author": "Evan You",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/vuejs/vue-cli/issues"
|
||||
},
|
||||
"homepage": "https://github.com/vuejs/vue-cli/packages/@vue/babel-preset-app#readme",
|
||||
"dependencies": {
|
||||
"@babel/plugin-syntax-jsx": "7 || ^7.0.0-beta || ^7.0.0-rc",
|
||||
"@babel/plugin-transform-runtime": "7 || ^7.0.0-beta || ^7.0.0-rc",
|
||||
"@babel/preset-env": "7 || ^7.0.0-beta || ^7.0.0-rc",
|
||||
"@babel/preset-stage-2": "7 || ^7.0.0-beta || ^7.0.0-rc",
|
||||
"@babel/runtime": "7 || ^7.0.0-beta || ^7.0.0-rc",
|
||||
"babel-helper-vue-jsx-merge-props": "^2.0.3",
|
||||
"babel-plugin-jsx-event-modifiers": "^2.0.5",
|
||||
"babel-plugin-jsx-v-model": "^2.0.3",
|
||||
"babel-plugin-transform-vue-jsx": "^3.5.0"
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
module.exports = api => {
|
||||
api.extendPackage({
|
||||
devDependencies: {
|
||||
'babel-preset-vue-app': '^2.0.0'
|
||||
'@vue/babel-preset-app': '^0.1.0'
|
||||
},
|
||||
babel: {
|
||||
presets: ['vue-app'] // TODO update babel-preset-vue-app
|
||||
presets: ['@vue/app']
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
},
|
||||
"homepage": "https://github.com/vuejs/vue-cli/packages/@vue/cli-plugin-babel#readme",
|
||||
"dependencies": {
|
||||
"babel-core": "^6.26.0",
|
||||
"babel-loader": "^7.1.2"
|
||||
"@babel/core": "7 || ^7.0.0-beta || ^7.0.0-rc",
|
||||
"babel-loader": "8 || ^8.0.0-beta || ^8.0.0-rc"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
|
||||
@@ -2,34 +2,10 @@ module.exports = (api, options) => {
|
||||
api.render('./template')
|
||||
api.extendPackage({
|
||||
scripts: {
|
||||
test: 'jest'
|
||||
test: 'vue-cli-service test'
|
||||
},
|
||||
devDependencies: {
|
||||
'jest': '^22.0.4',
|
||||
'vue-test-utils': '^1.0.0-beta.9'
|
||||
},
|
||||
'jest': {
|
||||
'moduleFileExtensions': [
|
||||
'js',
|
||||
'json',
|
||||
// tell Jest to handle *.vue files
|
||||
'vue'
|
||||
],
|
||||
'transform': {
|
||||
// process js with babel-jest
|
||||
'^.+\\.js$': '<rootDir>/node_modules/@vue/cli-plugin-unit-jest/node_modules/babel-jest',
|
||||
// process *.vue files with vue-jest
|
||||
'.*\\.(vue)$': '<rootDir>/node_modules/@vue/cli-plugin-unit-jest/node_modules/vue-jest'
|
||||
},
|
||||
// support the same @ -> src alias mapping in source code
|
||||
'moduleNameMapper': {
|
||||
'^@/(.*)$': '<rootDir>/src/$1'
|
||||
},
|
||||
// serializer for snapshots
|
||||
'snapshotSerializers': [
|
||||
'<rootDir>/node_modules/@vue/cli-plugin-unit-jest/node_modules/jest-serializer-vue'
|
||||
],
|
||||
'mapCoverage': true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1 +1,12 @@
|
||||
module.exports = () => {}
|
||||
module.exports = api => {
|
||||
api.registerCommand('test', {
|
||||
description: 'run unit tests with jest'
|
||||
}, args => {
|
||||
api.setMode('test')
|
||||
// for @vue/babel-preset-app
|
||||
process.env.VUE_CLI_BABEL_TARGET_NODE = true
|
||||
process.env.VUE_CLI_BABEL_TRANSPILE_MODULES = true
|
||||
|
||||
// TODO spawn jest w/ --config jest.config.js
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
// TODO check if jest auto merges options
|
||||
// if not, merge manually
|
||||
|
||||
module.exports = {
|
||||
'moduleFileExtensions': [
|
||||
'js',
|
||||
'json',
|
||||
// tell Jest to handle *.vue files
|
||||
'vue'
|
||||
],
|
||||
'transform': {
|
||||
// process js with babel-jest
|
||||
'^.+\\.js$': require.resolve('babel-jest'),
|
||||
// process *.vue files with vue-jest
|
||||
'.*\\.(vue)$': require.resolve('vue-jest')
|
||||
},
|
||||
// support the same @ -> src alias mapping in source code
|
||||
'moduleNameMapper': {
|
||||
'^@/(.*)$': '<rootDir>/src/$1'
|
||||
},
|
||||
// serializer for snapshots
|
||||
'snapshotSerializers': [
|
||||
require.resolve('jest-serializer-vue')
|
||||
],
|
||||
'mapCoverage': true
|
||||
}
|
||||
@@ -20,5 +20,11 @@
|
||||
"homepage": "https://github.com/vuejs/vue-cli/packages/@vue/cli-plugin-unit-jest#readme",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"dependencies": {
|
||||
"babel-jest": "^22.0.4",
|
||||
"jest": "^22.0.4",
|
||||
"jest-serializer-vue": "^0.3.0",
|
||||
"vue-jest": "^1.4.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
module.exports = api => {
|
||||
api.registerCommand('test', {
|
||||
description: 'run unit tests'
|
||||
description: 'run unit tests with mocha-webpack'
|
||||
}, args => {
|
||||
api.setEnv('test')
|
||||
api.setMode('test')
|
||||
// for @vue/babel-preset-app
|
||||
process.env.VUE_CLI_BABEL_TARGET_NODE = true
|
||||
require('./runner')(api.resolveWebpackConfig(), args)
|
||||
})
|
||||
|
||||
|
||||
@@ -10,12 +10,16 @@ module.exports = class PluginAPI {
|
||||
return path.resolve(this.service.context, _path)
|
||||
}
|
||||
|
||||
// set project mode.
|
||||
// this should be called by any registered command as early as possible.
|
||||
setMode (mode) {
|
||||
process.env.VUE_CLI_MODE = mode
|
||||
// by default, NODE_ENV and BABEL_ENV are set to "development" unless mode
|
||||
// is production. However this can be overwritten in .env files.
|
||||
process.env.NODE_ENV = process.env.BABE_ENV = mode === 'production'
|
||||
? mode
|
||||
: 'development'
|
||||
// is production or test. However this can be overwritten in .env files.
|
||||
process.env.NODE_ENV = process.env.BABE_ENV =
|
||||
(mode === 'production' || mode === 'test')
|
||||
? mode
|
||||
: 'development'
|
||||
// load .env files based on mode
|
||||
this.service.loadEnv(mode)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user