aboutsummaryrefslogtreecommitdiff
path: root/node_modules/@vue/babel-preset-app
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/@vue/babel-preset-app')
-rw-r--r--node_modules/@vue/babel-preset-app/README.md81
-rw-r--r--node_modules/@vue/babel-preset-app/index.js116
-rw-r--r--node_modules/@vue/babel-preset-app/package.json33
-rw-r--r--node_modules/@vue/babel-preset-app/polyfillsPlugin.js22
4 files changed, 252 insertions, 0 deletions
diff --git a/node_modules/@vue/babel-preset-app/README.md b/node_modules/@vue/babel-preset-app/README.md
new file mode 100644
index 00000000..f00efa47
--- /dev/null
+++ b/node_modules/@vue/babel-preset-app/README.md
@@ -0,0 +1,81 @@
+# @vue/babel-preset-app
+
+This is the default Babel preset used in all Vue CLI projects.
+
+## Included
+
+- [babel-preset-env](https://github.com/babel/babel/tree/master/packages/babel-preset-env)
+ - `modules: false`
+ - auto set to `'commonjs'` in Jest tests
+ - [`useBuiltIns: 'usage'`](#usebuiltins)
+ - `targets` is determined:
+ - using `browserslist` field in `package.json` when building for browsers
+ - set to `{ node: 'current' }` when running unit tests in Node.js
+- Includes `Promise` polyfill by default so that they are usable even in non-transpiled dependencies (only for environments that need it)
+- [@babel/plugin-transform-runtime](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-runtime)
+ - Only enabled for helpers since polyfills are handled by `babel-preset-env`
+- [dynamic import syntax](https://github.com/tc39/proposal-dynamic-import)
+- [Object rest spread](https://github.com/tc39/proposal-object-rest-spread)
+- [babel-preset-stage-2](https://github.com/babel/babel/tree/master/packages/babel-preset-stage-2)
+- Vue JSX support
+ - [@babel/plugin-syntax-jsx](https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-jsx)
+ - [babel-plugin-transform-vue-jsx](https://github.com/vuejs/babel-plugin-transform-vue-jsx)
+ - ~~[babel-plugin-jsx-event-modifiers](https://github.com/nickmessing/babel-plugin-jsx-event-modifiers)~~ (temporarily disabled until fixed for Babel 7)
+ - ~~[babel-plugin-jsx-v-model](https://github.com/nickmessing/babel-plugin-jsx-v-model)~~ (temporarily disabled until fixed for Babel 7)
+
+## Options
+
+### modules
+
+- Default:
+ - `false` when building with webpack
+ - `'commonjs'` when running tests in Jest.
+
+Explicitly set `modules` option for `babel-preset-env`. See [babel-preset-env docs](https://github.com/babel/babel/tree/master/packages/babel-preset-env#modules) for more details.
+
+### targets
+
+- Default:
+ - determined from `browserslist` field in `package.json` when building for browsers
+ - set to `{ node: 'current' }` when running unit tests in Node.js
+
+Explicitly set `targets` option for `babel-preset-env`. See [babel-preset-env docs](https://github.com/babel/babel/tree/master/packages/babel-preset-env#targets) for more details.
+
+### useBuiltIns
+
+- Default: `'usage'`
+- Allowed values: `'usage' | 'entry' | false`
+
+Explicitly set `useBuiltIns` option for `babel-preset-env`.
+
+The default value is `'usage'`, which adds imports to polyfills based on the usage in transpiled code. For example, if you use `Object.assign` in your code, the corresponding polyfill will be auto-imported if your target environment does not supports it.
+
+Note that the usage detection does not apply to your dependencies (which are excluded by `cli-plugin-babel` by default). If one of your dependencies need polyfills, you have a few options:
+
+1. **If the dependency is written in an ES version that your target environments do not support:** Add that dependency to the `transpileDependencies` option in `vue.config.js`. This would enable both syntax transforms and usage-based polyfill detection for that dependency.
+
+2. **If the dependency ships ES5 code and explicitly lists the polyfills needed:** you can pre-include the needed polyfills using the [polyfills](#polyfills) option for this preset.
+
+3. **If the dependency ships ES5 code, but uses ES6+ features without explicitly listing polyfill requirements (e.g. Vuetify):** Use `useBuiltIns: 'entry'` and then add `import '@babel/polyfill'` to your entry file. This will import **ALL** polyfills based on your `browserslist` targets so that you don't need to worry about dependency polyfills anymore, but will likely increase your final bundle size with some unused polyfills.
+
+See [babel-preset-env docs](https://github.com/babel/babel/tree/master/packages/babel-preset-env#usebuiltins) for more details.
+
+### polyfills
+
+- Default: `['es6.promise']`
+
+A list of [core-js](https://github.com/zloirock/core-js) polyfills to pre-include when using `useBuiltIns: 'usage'`. **These polyfills are automatically excluded if they are not needed for your target environments**.
+
+Use this option when you have 3rd party dependencies that are not processed by Babel but have specific polyfill requirements (e.g. Axios and Vuex require Promise support).
+
+### jsx
+
+- Default: `true`.
+
+Set to `false` to disable JSX support.
+
+### loose
+
+- Default: `false`.
+
+Setting this to `true` will generate code that is more performant but less spec-compliant.
diff --git a/node_modules/@vue/babel-preset-app/index.js b/node_modules/@vue/babel-preset-app/index.js
new file mode 100644
index 00000000..867568d4
--- /dev/null
+++ b/node_modules/@vue/babel-preset-app/index.js
@@ -0,0 +1,116 @@
+const path = require('path')
+
+const defaultPolyfills = [
+ 'es6.promise'
+]
+
+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 => {
+ return 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 {
+ polyfills: userPolyfills,
+ loose = false,
+ useBuiltIns = 'usage',
+ modules = false,
+ targets: rawTargets,
+ spec,
+ ignoreBrowserslistConfig,
+ configPath,
+ include,
+ exclude,
+ shippedProposals,
+ forceAllTransforms,
+ decoratorsLegacy
+ } = options
+
+ const targets = process.env.VUE_CLI_BABEL_TARGET_NODE
+ ? { node: 'current' }
+ : rawTargets
+
+ // included-by-default polyfills. These are common polyfills that 3rd party
+ // dependencies may rely on (e.g. Vuex relies on Promise), but since with
+ // useBuiltIns: 'usage' we won't be running Babel on these deps, they need to
+ // be force-included.
+ let polyfills
+ const buildTarget = process.env.VUE_CLI_TARGET || 'app'
+ if (buildTarget === 'app' && useBuiltIns === 'usage') {
+ polyfills = getPolyfills(targets, userPolyfills || defaultPolyfills, {
+ ignoreBrowserslistConfig,
+ configPath
+ })
+ plugins.push([require('./polyfillsPlugin'), { polyfills }])
+ } else {
+ polyfills = []
+ }
+
+ const envOptions = {
+ spec,
+ loose,
+ modules,
+ targets,
+ useBuiltIns,
+ ignoreBrowserslistConfig,
+ configPath,
+ include,
+ exclude: polyfills.concat(exclude || []),
+ shippedProposals,
+ forceAllTransforms
+ }
+
+ // cli-plugin-jest sets this to true because Jest runs without bundling
+ if (process.env.VUE_CLI_BABEL_TRANSPILE_MODULES) {
+ envOptions.modules = 'commonjs'
+ // necessary for dynamic import to work in tests
+ plugins.push(require('babel-plugin-dynamic-import-node'))
+ }
+
+ // pass options along to babel-preset-env
+ presets.push([require('@babel/preset-env'), envOptions])
+
+ // stage 2. This includes some important transforms, e.g. dynamic import
+ // and rest object spread.
+ presets.push([require('@babel/preset-stage-2'), {
+ loose,
+ useBuiltIns: useBuiltIns !== false,
+ decoratorsLegacy: decoratorsLegacy !== false
+ }])
+
+ // transform runtime, but only for helpers
+ plugins.push([require('@babel/plugin-transform-runtime'), {
+ polyfill: false,
+ regenerator: useBuiltIns !== 'usage',
+ useBuiltIns: useBuiltIns !== false,
+ useESModules: !process.env.VUE_CLI_BABEL_TRANSPILE_MODULES,
+ moduleName: path.dirname(require.resolve('@babel/runtime/package.json'))
+ }])
+
+ return {
+ presets,
+ plugins
+ }
+}
diff --git a/node_modules/@vue/babel-preset-app/package.json b/node_modules/@vue/babel-preset-app/package.json
new file mode 100644
index 00000000..d0c8dcde
--- /dev/null
+++ b/node_modules/@vue/babel-preset-app/package.json
@@ -0,0 +1,33 @@
+{
+ "name": "@vue/babel-preset-app",
+ "version": "3.0.0-beta.11",
+ "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.0.0-beta.47",
+ "@babel/plugin-transform-runtime": "7.0.0-beta.47",
+ "@babel/preset-env": "7.0.0-beta.47",
+ "@babel/preset-stage-2": "7.0.0-beta.47",
+ "@babel/runtime": "7.0.0-beta.47",
+ "babel-helper-vue-jsx-merge-props": "^2.0.3",
+ "babel-plugin-dynamic-import-node": "^1.2.0",
+ "babel-plugin-transform-vue-jsx": "^4.0.1"
+ }
+}
diff --git a/node_modules/@vue/babel-preset-app/polyfillsPlugin.js b/node_modules/@vue/babel-preset-app/polyfillsPlugin.js
new file mode 100644
index 00000000..0949c253
--- /dev/null
+++ b/node_modules/@vue/babel-preset-app/polyfillsPlugin.js
@@ -0,0 +1,22 @@
+// add polyfill imports to the first file encountered.
+module.exports = ({ types }) => {
+ let entryFile
+ return {
+ name: 'vue-cli-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')
+ polyfills.forEach(p => {
+ createImport(path, p)
+ })
+ }
+ }
+ }
+}