feat: move @nuxtjs/babel-preset-app into nuxt mono-repo (#4205)

This commit is contained in:
Clark Du 2018-10-26 18:58:21 +01:00 committed by Pooya Parsa
parent 106141f74c
commit ae9de93a45
7 changed files with 148 additions and 19 deletions

View File

@ -0,0 +1,24 @@
{
"name": "@nuxt/babel-preset-app",
"version": "2.2.0",
"description": "babel-preset-app for nuxt.js",
"repository": "nuxt/nuxt.js",
"license": "MIT",
"author": "Evan You",
"contributors": [
"Clark Du"
],
"main": "src/index.js",
"dependencies": {
"@babel/core": "^7.1.0",
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/plugin-proposal-decorators": "^7.1.0",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/plugin-syntax-jsx": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.1.0",
"@babel/preset-env": "^7.1.0",
"@babel/runtime": "^7.0.0",
"babel-helper-vue-jsx-merge-props": "^2.0.3",
"babel-plugin-transform-vue-jsx": "^4.0.1"
}
}

View File

@ -0,0 +1,97 @@
const defaultPolyfills = [
// Promise polyfill alone doesn't work in IE,
// Needs this as well. see: #1642
'es6.array.iterator',
// This is required for webpack code splitting, vuex etc.
'es6.promise',
// #2012 es6.promise replaces native Promise in FF and causes missing finally
'es7.promise.finally'
]
function getPolyfills(targets, includes, { ignoreBrowserslistConfig, configPath }) {
const { isPluginRequired } = require('@babel/preset-env')
const builtInsList = require('@babel/preset-env/data/built-ins.json')
const getTargets = require('@babel/preset-env/lib/targets-parser').default
const builtInTargets = getTargets(targets, {
ignoreBrowserslistConfig,
configPath
})
return includes.filter(item => isPluginRequired(builtInTargets, builtInsList[item]))
}
module.exports = (context, options = {}) => {
const presets = []
const plugins = []
// JSX
if (options.jsx !== false) {
plugins.push(
require('@babel/plugin-syntax-jsx'),
require('babel-plugin-transform-vue-jsx')
// require('babel-plugin-jsx-event-modifiers'),
// require('babel-plugin-jsx-v-model')
)
}
const modern = !!options.modern
const {
buildTarget,
loose = false,
useBuiltIns = 'usage',
modules = false,
polyfills: userPolyfills,
ignoreBrowserslistConfig = modern,
configPath,
forceAllTransforms,
decoratorsLegacy
} = options
let targets = options.targets
if (modern === true) {
targets = { esmodules: true }
} else if (targets === undefined) {
targets = buildTarget === 'server' ? { node: 'current' } : { ie: 9 }
}
let polyfills
if (modern === false && useBuiltIns === 'usage' && buildTarget === 'client') {
polyfills = getPolyfills(targets, userPolyfills || defaultPolyfills, {
ignoreBrowserslistConfig,
configPath
})
plugins.push([require('./polyfills-plugin'), { polyfills }])
} else {
polyfills = []
}
// Pass options along to babel-preset-env
presets.push([
require('@babel/preset-env'), {
loose,
modules,
targets,
useBuiltIns,
forceAllTransforms,
ignoreBrowserslistConfig,
exclude: polyfills
}
])
plugins.push(
require('@babel/plugin-syntax-dynamic-import'),
[require('@babel/plugin-proposal-decorators'), { legacy: decoratorsLegacy !== false }],
[require('@babel/plugin-proposal-class-properties'), { loose }]
)
// Transform runtime, but only for helpers
plugins.push([require('@babel/plugin-transform-runtime'), {
regenerator: useBuiltIns !== 'usage'
}])
return {
presets,
plugins
}
}

View File

@ -0,0 +1,24 @@
// Add polyfill imports to the first file encountered.
module.exports = ({ types }) => {
let entryFile
return {
name: 'inject-polyfills',
visitor: {
Program(path, state) {
if (!entryFile) {
entryFile = state.filename
} else if (state.filename !== entryFile) {
return
}
const { polyfills } = state.opts
const { createImport } = require('@babel/preset-env/lib/utils')
// Imports are injected in reverse order
polyfills.slice().reverse().forEach((p) => {
createImport(path, p)
})
}
}
}
}

View File

@ -10,8 +10,8 @@
"dependencies": {
"@babel/core": "^7.1.2",
"@babel/polyfill": "^7.0.0",
"@nuxt/babel-preset-app": "^2.2.0",
"@nuxt/common": "^2.2.0",
"@nuxtjs/babel-preset-app": "^0.7.0",
"@nuxtjs/friendly-errors-webpack-plugin": "^2.0.2",
"babel-loader": "^8.0.4",
"cache-loader": "^1.2.2",

View File

@ -43,7 +43,7 @@ export default class WebpackBaseConfig {
if (!options.babelrc && !options.presets) {
options.presets = [
[
require.resolve('@nuxtjs/babel-preset-app'),
require.resolve('@nuxt/babel-preset-app'),
{
buildTarget: this.isServer ? 'server' : 'client'
}

View File

@ -12,7 +12,7 @@ async function main() {
// Create a dev-only entrypoint to the src
for (const pkg of workspacePackages) {
if (!pkg.pkg.main) {
if (!pkg.pkg.main || !pkg.options.build) {
continue
}
consola.info(pkg.pkg.main)

View File

@ -1333,22 +1333,6 @@
resolved "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-1.1.2.tgz#54c5a964462be3d4d78af631363c18d6fa91ac26"
integrity sha512-yprFYuno9FtNsSHVlSWd+nRlmGoAbqbeCwOryP6sC/zoCjhpArcRMYp19EvpSUSizJAlsXEwJv+wcWS9XaXdMw==
"@nuxtjs/babel-preset-app@^0.7.0":
version "0.7.0"
resolved "https://registry.npmjs.org/@nuxtjs/babel-preset-app/-/babel-preset-app-0.7.0.tgz#b208a95e0a053259c29b99a9e4ca9ea2604dbdd2"
integrity sha512-gYyFNa+etbsYs5SN7KT2SJxARPgKptBh5N3r66TzSE4kerFdSn7Gd324FoNKfqAnkXv7FsHZflKWoLFxYgn8UQ==
dependencies:
"@babel/core" "^7.1.0"
"@babel/plugin-proposal-class-properties" "^7.1.0"
"@babel/plugin-proposal-decorators" "^7.1.0"
"@babel/plugin-syntax-dynamic-import" "^7.0.0"
"@babel/plugin-syntax-jsx" "^7.0.0"
"@babel/plugin-transform-runtime" "^7.1.0"
"@babel/preset-env" "^7.1.0"
"@babel/runtime" "^7.0.0"
babel-helper-vue-jsx-merge-props "^2.0.3"
babel-plugin-transform-vue-jsx "^4.0.1"
"@nuxtjs/devalue@^1.0.1":
version "1.0.1"
resolved "https://registry.npmjs.org/@nuxtjs/devalue/-/devalue-1.0.1.tgz#661f16ed4c5d4bf64ab8b6e66fa1aa16bc57d504"