feat: upgrade to Babel 7 (#3667)

This commit is contained in:
Clark Du 2018-08-10 14:45:58 +01:00 committed by GitHub
parent b243219461
commit 9b060f3be1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 795 additions and 569 deletions

View File

@ -2,10 +2,10 @@
"env": { "env": {
"test": { "test": {
"presets": [ "presets": [
["env", { ["@babel/env", {
"targets": { "targets": {
"node": "current" "node": "current"
} }
}] }]
] ]
} }

View File

@ -20,8 +20,9 @@ import * as people from '~/store/modules/people'
const PeopleAction = namespace(people.name, Action) const PeopleAction = namespace(people.name, Action)
export default
@Component({}) @Component({})
export default class Card extends Vue { class Card extends Vue {
@Prop() person @Prop() person
@PeopleAction select @PeopleAction select
} }

View File

@ -24,12 +24,13 @@ import * as people from '~/store/modules/people'
const PeopleState = namespace(people.name, State) const PeopleState = namespace(people.name, State)
const PeopleGetter = namespace(people.name, Getter) const PeopleGetter = namespace(people.name, Getter)
export default
@Component({ @Component({
components: { components: {
Card Card
} }
}) })
export default class extends Vue { class extends Vue {
@PeopleState selected @PeopleState selected
@PeopleState people @PeopleState people
@PeopleGetter selectedPerson @PeopleGetter selectedPerson

View File

@ -13,12 +13,13 @@
import Vue from 'vue' import Vue from 'vue'
import Component from 'nuxt-class-component' import Component from 'nuxt-class-component'
export default
@Component({ @Component({
props: { props: {
env: String env: String
} }
}) })
export default class Base extends Vue { class Base extends Vue {
// initial data // initial data
msg = 123 msg = 123

View File

@ -13,8 +13,9 @@
import Component from 'nuxt-class-component' import Component from 'nuxt-class-component'
import Base from '@/components/Base' import Base from '@/components/Base'
export default
@Component @Component
export default class Child extends Base { class Child extends Base {
// override parent method // override parent method
greet() { greet() {
console.log('child greeting: ' + this.msg) // eslint-disable-line no-console console.log('child greeting: ' + this.msg) // eslint-disable-line no-console

View File

@ -1,7 +0,0 @@
export default {
build: {
babel: {
plugins: ['transform-decorators-legacy', 'transform-class-properties']
}
}
}

View File

@ -1,10 +1,8 @@
{ {
"name": "example-vue-class-component", "name": "example-vue-class-component",
"dependencies": { "dependencies": {
"babel-plugin-transform-class-properties": "^6.24.1", "nuxt-edge": "latest",
"babel-plugin-transform-decorators-legacy": "^1.3.4", "nuxt-class-component": "latest"
"nuxt": "latest",
"nuxt-class-component": "^1.0.4"
}, },
"scripts": { "scripts": {
"dev": "nuxt", "dev": "nuxt",

View File

@ -7,10 +7,11 @@ import Vue from 'vue'
import Component from 'nuxt-class-component' import Component from 'nuxt-class-component'
import Child from '@/components/Child' import Child from '@/components/Child'
export default
@Component({ @Component({
components: { Child } components: { Child }
}) })
export default class App extends Vue { class App extends Vue {
asyncData({ req }) { asyncData({ req }) {
return { env: req ? 'server' : 'client' } return { env: req ? 'server' : 'client' }
} }

View File

@ -1,4 +1,3 @@
import 'es6-promise/auto'
import Vue from 'vue' import Vue from 'vue'
import Meta from 'vue-meta' import Meta from 'vue-meta'
import { createRouter } from './router.js' import { createRouter } from './router.js'

View File

@ -32,9 +32,9 @@ export default class WebpackBaseConfig {
if (!options.babelrc && !options.presets) { if (!options.babelrc && !options.presets) {
options.presets = [ options.presets = [
[ [
require.resolve('babel-preset-vue-app'), require.resolve('@nuxtjs/babel-preset-app'),
{ {
targets: this.isServer ? { node: 'current' } : { ie: 9, uglify: true } buildTarget: this.isServer ? 'server' : 'client'
} }
] ]
] ]
@ -281,7 +281,6 @@ export default class WebpackBaseConfig {
modules: webpackModulesDir modules: webpackModulesDir
}, },
module: { module: {
noParse: /es6-promise\.js$/, // Avoid webpack shimming process
rules: this.rules() rules: this.rules()
}, },
plugins: this.plugins() plugins: this.plugins()

View File

@ -91,7 +91,7 @@ export default class WebpackClientConfig extends WebpackBaseConfig {
config.optimization.splitChunks.cacheGroups.commons === undefined config.optimization.splitChunks.cacheGroups.commons === undefined
) { ) {
config.optimization.splitChunks.cacheGroups.commons = { config.optimization.splitChunks.cacheGroups.commons = {
test: /node_modules[\\/](vue|vue-loader|vue-router|vuex|vue-meta|core-js|babel-runtime|es6-promise|axios|webpack|setimmediate|timers-browserify|process|regenerator-runtime|cookie|js-cookie|is-buffer|dotprop|nuxt\.js)[\\/]/, test: /node_modules[\\/](vue|vue-loader|vue-router|vuex|vue-meta|core-js|@babel\/runtime|axios|webpack|setimmediate|timers-browserify|process|regenerator-runtime|cookie|js-cookie|is-buffer|dotprop|nuxt\.js)[\\/]/,
chunks: 'all', chunks: 'all',
priority: 10, priority: 10,
name: true name: true

View File

@ -65,7 +65,6 @@ export default class WebpackServerConfig extends BaseConfig {
config.externals.push( config.externals.push(
nodeExternals({ nodeExternals({
whitelist: [ whitelist: [
/es6-promise|\.(?!(?:js|json)$).{1,5}$/i,
/\.css$/, /\.css$/,
/\?vue&type=style/, /\?vue&type=style/,
...this.options.build.transpile ...this.options.build.transpile

View File

@ -22,7 +22,7 @@ export default class PerfLoader {
} }
warmupAll() { warmupAll() {
this.warmup(this.workerPools.js, ['babel-loader', 'babel-preset-env']) this.warmup(this.workerPools.js, ['babel-loader', '@babel/preset-env'])
this.warmup(this.workerPools.css, ['css-loader']) this.warmup(this.workerPools.css, ['css-loader'])
} }

View File

@ -1,4 +1,4 @@
import 'babel-polyfill' import '@babel/polyfill'
import consola from 'consola' import consola from 'consola'

View File

@ -70,12 +70,12 @@
"npm": ">=5.0.0" "npm": ">=5.0.0"
}, },
"dependencies": { "dependencies": {
"@babel/core": "7.0.0-rc.1",
"@nuxtjs/babel-preset-app": "^0.3.0",
"@nuxtjs/friendly-errors-webpack-plugin": "^2.0.2", "@nuxtjs/friendly-errors-webpack-plugin": "^2.0.2",
"@nuxtjs/youch": "^4.2.3", "@nuxtjs/youch": "^4.2.3",
"autoprefixer": "^8.6.4", "autoprefixer": "^8.6.4",
"babel-core": "^6.26.3", "babel-loader": "^8.0.0-beta",
"babel-loader": "^7.1.4",
"babel-preset-vue-app": "^2.0.0",
"cache-loader": "^1.2.2", "cache-loader": "^1.2.2",
"caniuse-lite": "^1.0.30000862", "caniuse-lite": "^1.0.30000862",
"chalk": "^2.4.1", "chalk": "^2.4.1",
@ -86,7 +86,6 @@
"css-loader": "^1.0.0", "css-loader": "^1.0.0",
"cssnano": "^4.0.5", "cssnano": "^4.0.5",
"debug": "^3.1.0", "debug": "^3.1.0",
"es6-promise": "^4.2.4",
"esm": "^3.0.74", "esm": "^3.0.74",
"etag": "^1.8.1", "etag": "^1.8.1",
"file-loader": "^1.1.11", "file-loader": "^1.1.11",
@ -138,11 +137,11 @@
"webpackbar": "^2.6.1" "webpackbar": "^2.6.1"
}, },
"devDependencies": { "devDependencies": {
"babel-eslint": "^8.2.6", "@babel/plugin-external-helpers": "7.0.0-rc.1",
"@babel/polyfill": "7.0.0-rc.1",
"babel-core": "^7.0.0-0",
"babel-eslint": "^9.0.0-beta",
"babel-jest": "^23.0.1", "babel-jest": "^23.0.1",
"babel-plugin-external-helpers": "^6.22.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"codecov": "^3.0.2", "codecov": "^3.0.2",
"cross-env": "^5.2.0", "cross-env": "^5.2.0",
"eslint": "^4.19.1", "eslint": "^4.19.1",
@ -168,7 +167,7 @@
"request-promise-native": "^1.0.5", "request-promise-native": "^1.0.5",
"rimraf": "^2.6.2", "rimraf": "^2.6.2",
"rollup": "^0.59.4", "rollup": "^0.59.4",
"rollup-plugin-babel": "^3.0.4", "rollup-plugin-babel": "^4.0.0-beta.8",
"rollup-plugin-commonjs": "^9.1.3", "rollup-plugin-commonjs": "^9.1.3",
"rollup-plugin-json": "^3.0.0", "rollup-plugin-json": "^3.0.0",
"rollup-plugin-license": "^0.7.0" "rollup-plugin-license": "^0.7.0"

View File

@ -9,7 +9,7 @@ const nodeBuiltIn = ['path', 'fs', 'module', 'crypto', 'util']
// Optional dependencies that user should install on demand // Optional dependencies that user should install on demand
const optionalDependencies = [ const optionalDependencies = [
// legacy build users need this // legacy build users need this
'babel-polyfill' '@babel/polyfill'
] ]
const externals = [].concat( const externals = [].concat(

View File

@ -10,14 +10,14 @@ export default config({
exclude: 'node_modules/**', exclude: 'node_modules/**',
presets: [ presets: [
[ [
'env', '@babel/preset-env',
{ {
'modules': false 'modules': false
} }
] ]
], ],
plugins: [ plugins: [
'external-helpers' '@babel/external-helpers'
] ]
}) })
] ]

View File

@ -18,7 +18,7 @@ describe('webpack configuration', () => {
perfLoader.warmup = jest.fn() perfLoader.warmup = jest.fn()
perfLoader.warmupAll() perfLoader.warmupAll()
expect(perfLoader.warmup).toHaveBeenCalledTimes(2) expect(perfLoader.warmup).toHaveBeenCalledTimes(2)
expect(perfLoader.warmup).toHaveBeenCalledWith(js, ['babel-loader', 'babel-preset-env']) expect(perfLoader.warmup).toHaveBeenCalledWith(js, ['babel-loader', '@babel/preset-env'])
expect(perfLoader.warmup).toHaveBeenCalledWith(css, ['css-loader']) expect(perfLoader.warmup).toHaveBeenCalledWith(css, ['css-loader'])
const loaders = perfLoader.pool('js', { loader: 'test-perf-loader' }) const loaders = perfLoader.pool('js', { loader: 'test-perf-loader' })

View File

@ -1,5 +1,4 @@
// eslint-disable // eslint-disable
require('babel-polyfill')
require('consola').clear().add({ require('consola').clear().add({
log: jest.fn() log: jest.fn()
}) })

1289
yarn.lock

File diff suppressed because it is too large Load Diff