build: target es5

This commit is contained in:
Evan You 2022-05-19 16:08:46 +08:00
parent 9949ab5d14
commit 19a5a35529
20 changed files with 37 additions and 64338 deletions

1
.gitignore vendored
View File

@ -17,3 +17,4 @@ packages/vue-server-renderer/server-plugin.js
packages/vue-server-renderer/client-plugin.js
packages/vue-template-compiler/build.js
.vscode
dist

122
dist/README.md vendored
View File

@ -1,122 +0,0 @@
## Explanation of Build Files
| | UMD | CommonJS | ES Module |
| --- | --- | --- | --- |
| **Full** | vue.js | vue.common.js | vue.esm.js |
| **Runtime-only** | vue.runtime.js | vue.runtime.common.js | vue.runtime.esm.js |
| **Full (production)** | vue.min.js | | |
| **Runtime-only (production)** | vue.runtime.min.js | | |
### Terms
- **Full**: builds that contain both the compiler and the runtime.
- **Compiler**: code that is responsible for compiling template strings into JavaScript render functions.
- **Runtime**: code that is responsible for creating Vue instances, rendering and patching virtual DOM, etc. Basically everything minus the compiler.
- **[UMD](https://github.com/umdjs/umd)**: UMD builds can be used directly in the browser via a `<script>` tag. The default file from Unpkg CDN at [https://unpkg.com/vue](https://unpkg.com/vue) is the Runtime + Compiler UMD build (`vue.js`).
- **[CommonJS](http://wiki.commonjs.org/wiki/Modules/1.1)**: CommonJS builds are intended for use with older bundlers like [browserify](http://browserify.org/) or [webpack 1](https://webpack.github.io). The default file for these bundlers (`pkg.main`) is the Runtime only CommonJS build (`vue.runtime.common.js`).
- **[ES Module](http://exploringjs.com/es6/ch_modules.html)**: ES module builds are intended for use with modern bundlers like [webpack 2](https://webpack.js.org) or [rollup](http://rollupjs.org/). The default file for these bundlers (`pkg.module`) is the Runtime only ES Module build (`vue.runtime.esm.js`).
### Runtime + Compiler vs. Runtime-only
If you need to compile templates on the fly (e.g. passing a string to the `template` option, or mounting to an element using its in-DOM HTML as the template), you will need the compiler and thus the full build.
When using `vue-loader` or `vueify`, templates inside `*.vue` files are compiled into JavaScript at build time. You don't really need the compiler in the final bundle, and can therefore, use the runtime-only build.
Since the runtime-only builds are roughly 30% lighter-weight than their full-build counterparts, you should use it whenever you can. If you wish to use the full build instead, you need to configure an alias in your bundler.
#### Webpack
``` js
module.exports = {
// ...
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js' // 'vue/dist/vue.common.js' for webpack 1
}
}
}
```
#### Rollup
``` js
const alias = require('rollup-plugin-alias')
rollup({
// ...
plugins: [
alias({
'vue': 'vue/dist/vue.esm.js'
})
]
})
```
#### Browserify
Add to your project's `package.json`:
``` js
{
// ...
"browser": {
"vue": "vue/dist/vue.common.js"
}
}
```
### Development vs. Production Mode
Development/production modes are hard-coded for the UMD builds: the un-minified files are for development, and the minified files are for production.
CommonJS and ES Module builds are intended for bundlers, therefore we don't provide minified versions for them. You will be responsible for minifying the final bundle yourself.
CommonJS and ES Module builds also preserve raw checks for `process.env.NODE_ENV` to determine the mode they should run in. You should use appropriate bundler configurations to replace these environment variables in order to control which mode Vue will run in. Replacing `process.env.NODE_ENV` with string literals also allows minifiers like UglifyJS to completely drop the development-only code blocks, reducing final file size.
#### Webpack
Use Webpack's [DefinePlugin](https://webpack.js.org/plugins/define-plugin/):
``` js
var webpack = require('webpack')
module.exports = {
// ...
plugins: [
// ...
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
})
]
}
```
#### Rollup
Use [rollup-plugin-replace](https://github.com/rollup/rollup-plugin-replace):
``` js
const replace = require('rollup-plugin-replace')
rollup({
// ...
plugins: [
replace({
'process.env.NODE_ENV': JSON.stringify('production')
})
]
}).then(...)
```
#### Browserify
Apply a global [envify](https://github.com/hughsk/envify) transform to your bundle.
``` bash
NODE_ENV=production browserify -g envify -e main.js | uglifyjs -c -m > build.js
```

10448
dist/vue.common.dev.js vendored

File diff suppressed because it is too large Load Diff

5
dist/vue.common.js vendored
View File

@ -1,5 +0,0 @@
if (process.env.NODE_ENV === 'production') {
module.exports = require('./vue.common.prod.js')
} else {
module.exports = require('./vue.common.dev.js')
}

File diff suppressed because one or more lines are too long

10446
dist/vue.esm.browser.js vendored

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

10500
dist/vue.esm.js vendored

File diff suppressed because it is too large Load Diff

10454
dist/vue.js vendored

File diff suppressed because it is too large Load Diff

11
dist/vue.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +0,0 @@
if (process.env.NODE_ENV === 'production') {
module.exports = require('./vue.runtime.common.prod.js')
} else {
module.exports = require('./vue.runtime.common.dev.js')
}

File diff suppressed because one or more lines are too long

7443
dist/vue.runtime.esm.js vendored

File diff suppressed because it is too large Load Diff

7410
dist/vue.runtime.js vendored

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -77,7 +77,6 @@
"@babel/preset-typescript": "^7.16.7",
"@babel/register": "^7.17.7",
"@rollup/plugin-alias": "^3.1.9",
"@rollup/plugin-buble": "^0.21.3",
"@rollup/plugin-commonjs": "^22.0.0",
"@rollup/plugin-node-resolve": "^13.2.1",
"@rollup/plugin-replace": "^4.0.0",
@ -98,7 +97,7 @@
"babel-plugin-transform-vue-jsx": "^4.0.1",
"babel-preset-flow-vue": "^1.0.0",
"buble": "^0.20.0",
"chalk": "^5.0.1",
"chalk": "^4.0.0",
"chromedriver": "^100.0.0",
"codecov": "^3.8.3",
"commitizen": "^4.2.4",

View File

@ -1,5 +1,4 @@
const path = require('path')
const buble = require('@rollup/plugin-buble')
const alias = require('@rollup/plugin-alias')
const cjs = require('@rollup/plugin-commonjs')
const replace = require('@rollup/plugin-replace')
@ -7,7 +6,9 @@ const node = require('@rollup/plugin-node-resolve').nodeResolve
const ts = require('rollup-plugin-typescript2')
const version = process.env.VERSION || require('../package.json').version
const weexVersion = process.env.WEEX_VERSION || require('../packages/weex-vue-framework/package.json').version
const weexVersion =
process.env.WEEX_VERSION ||
require('../packages/weex-vue-framework/package.json').version
const featureFlags = require('./feature-flags')
const banner =
@ -18,16 +19,16 @@ const banner =
' */'
const weexFactoryPlugin = {
intro () {
intro() {
return 'module.exports = function weexFactory (exports, document) {'
},
outro () {
outro() {
return '}'
}
}
const aliases = require('./alias')
const resolve = p => {
const resolve = (p) => {
const base = p.split('/')[0]
if (aliases[base]) {
return path.resolve(aliases[base], p.slice(base.length + 1))
@ -143,7 +144,9 @@ const builds = {
entry: resolve('web/entry-compiler.ts'),
dest: resolve('packages/vue-template-compiler/build.js'),
format: 'cjs',
external: Object.keys(require('../packages/vue-template-compiler/package.json').dependencies)
external: Object.keys(
require('../packages/vue-template-compiler/package.json').dependencies
)
},
// Web compiler (UMD for in-browser use).
'web-compiler-browser': {
@ -160,14 +163,18 @@ const builds = {
dest: resolve('packages/vue-server-renderer/build.dev.js'),
format: 'cjs',
env: 'development',
external: Object.keys(require('../packages/vue-server-renderer/package.json').dependencies)
external: Object.keys(
require('../packages/vue-server-renderer/package.json').dependencies
)
},
'web-server-renderer-prod': {
entry: resolve('web/entry-server-renderer.ts'),
dest: resolve('packages/vue-server-renderer/build.prod.js'),
format: 'cjs',
env: 'production',
external: Object.keys(require('../packages/vue-server-renderer/package.json').dependencies)
external: Object.keys(
require('../packages/vue-server-renderer/package.json').dependencies
)
},
'web-server-renderer-basic': {
entry: resolve('web/entry-server-basic-renderer.ts'),
@ -181,13 +188,17 @@ const builds = {
entry: resolve('server/webpack-plugin/server.ts'),
dest: resolve('packages/vue-server-renderer/server-plugin.js'),
format: 'cjs',
external: Object.keys(require('../packages/vue-server-renderer/package.json').dependencies)
external: Object.keys(
require('../packages/vue-server-renderer/package.json').dependencies
)
},
'web-server-renderer-webpack-client-plugin': {
entry: resolve('server/webpack-plugin/client.ts'),
dest: resolve('packages/vue-server-renderer/client-plugin.js'),
format: 'cjs',
external: Object.keys(require('../packages/vue-server-renderer/package.json').dependencies)
external: Object.keys(
require('../packages/vue-server-renderer/package.json').dependencies
)
},
// Weex runtime factory
'weex-factory': {
@ -210,11 +221,13 @@ const builds = {
entry: resolve('weex/entry-compiler.ts'),
dest: resolve('packages/weex-template-compiler/build.js'),
format: 'cjs',
external: Object.keys(require('../packages/weex-template-compiler/package.json').dependencies)
external: Object.keys(
require('../packages/weex-template-compiler/package.json').dependencies
)
}
}
function genConfig (name) {
function genConfig(name) {
const opts = builds[name]
// console.log('__dir', __dirname)
@ -227,11 +240,14 @@ function genConfig (name) {
}),
ts({
tsconfig: path.resolve(__dirname, '../', 'tsconfig.json'),
cacheRoot: path.resolve(__dirname, '../','node_modules/.rts2_cache'),
cacheRoot: path.resolve(__dirname, '../', 'node_modules/.rts2_cache'),
tsconfigOverride: {
compilerOptions: {
target: opts.transpile === false ? 'esnext' : 'es5'
},
exclude: ['test', 'test-dts']
}
}),
})
].concat(opts.plugins || []),
output: {
file: opts.dest,
@ -256,7 +272,7 @@ function genConfig (name) {
__VERSION__: version
}
// feature flags
Object.keys(featureFlags).forEach(key => {
Object.keys(featureFlags).forEach((key) => {
vars[`process.env.${key}`] = featureFlags[key]
})
// build-specific env
@ -267,10 +283,6 @@ function genConfig (name) {
vars.preventAssignment = true
config.plugins.push(replace(vars))
// if (opts.transpile !== false) {
// config.plugins.push(buble())
// }
Object.defineProperty(config, '_name', {
enumerable: false,
value: name

View File

@ -3,11 +3,11 @@
"baseUrl": ".",
"outDir": "dist",
"sourceMap": true,
"target": "ESNext",
"target": "es5",
"module": "ESNext",
"moduleResolution": "node",
"strict": true,
"allowJs": true,
"noImplicitAny": false,
"noImplicitThis": false,

View File

@ -1138,15 +1138,6 @@
dependencies:
slash "^3.0.0"
"@rollup/plugin-buble@^0.21.3":
version "0.21.3"
resolved "https://registry.yarnpkg.com/@rollup/plugin-buble/-/plugin-buble-0.21.3.tgz#1649a915b1d051a4f430d40e7734a7f67a69b33e"
integrity sha512-Iv8cCuFPnMdqV4pcyU+OrfjOfagPArRQ1PyQjx5KgHk3dARedI+8PNTLSMpJts0lQJr8yF2pAU4GxpxCBJ9HYw==
dependencies:
"@rollup/pluginutils" "^3.0.8"
"@types/buble" "^0.19.2"
buble "^0.20.0"
"@rollup/plugin-commonjs@^22.0.0":
version "22.0.0"
resolved "https://registry.yarnpkg.com/@rollup/plugin-commonjs/-/plugin-commonjs-22.0.0.tgz#f4d87016e2fbf187a593ab9f46626fe05b59e8bd"
@ -1180,7 +1171,7 @@
"@rollup/pluginutils" "^3.1.0"
magic-string "^0.25.7"
"@rollup/pluginutils@^3.0.8", "@rollup/pluginutils@^3.1.0":
"@rollup/pluginutils@^3.1.0":
version "3.1.0"
resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-3.1.0.tgz#706b4524ee6dc8b103b3c995533e5ad680c02b9b"
integrity sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==
@ -1244,13 +1235,6 @@
resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.2.tgz#423c77877d0569db20e1fc80885ac4118314010e"
integrity sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA==
"@types/buble@^0.19.2":
version "0.19.2"
resolved "https://registry.yarnpkg.com/@types/buble/-/buble-0.19.2.tgz#a4289d20b175b3c206aaad80caabdabe3ecdfdd1"
integrity sha512-uUD8zIfXMKThmFkahTXDGI3CthFH1kMg2dOm3KLi4GlC5cbARA64bEcUMbbWdWdE73eoc/iBB9PiTMqH0dNS2Q==
dependencies:
magic-string "^0.25.0"
"@types/cacheable-request@^6.0.1":
version "6.0.2"
resolved "https://registry.yarnpkg.com/@types/cacheable-request/-/cacheable-request-6.0.2.tgz#c324da0197de0a98a2312156536ae262429ff6b9"
@ -2664,11 +2648,6 @@ chalk@^4.0.0, chalk@^4.1.0, chalk@^4.1.2:
ansi-styles "^4.1.0"
supports-color "^7.1.0"
chalk@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-5.0.1.tgz#ca57d71e82bb534a296df63bbacc4a1c22b2a4b6"
integrity sha512-Fo07WOYGqMfCWHOzSXOt2CxDbC6skS/jO9ynEcmpANMoPrD+W1r1K6Vx7iNm+AQmETU1Xr2t+n8nzkV9t6xh3w==
change-case@^4.1.1:
version "4.1.2"
resolved "https://registry.yarnpkg.com/change-case/-/change-case-4.1.2.tgz#fedfc5f136045e2398c0410ee441f95704641e12"
@ -6517,7 +6496,7 @@ lru-cache@^7.8.1:
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-7.9.0.tgz#29c2a989b6c10f32ceccc66ff44059e1490af3e1"
integrity sha512-lkcNMUKqdJk96TuIXUidxaPuEg5sJo/+ZyVE2BDFnuZGzwXem7d8582eG8vbu4todLfT14snP6iHriCHXXi5Rw==
magic-string@^0.25.0, magic-string@^0.25.7:
magic-string@^0.25.7:
version "0.25.9"
resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.25.9.tgz#de7f9faf91ef8a1c91d02c2e5314c8277dbcdd1c"
integrity sha512-RmF0AsMzgt25qzqqLc1+MbHmhdx0ojF2Fvs4XnOqz2ZOBXzzkEwc/dJQZCYHAn7v1jbVOjAZfK8msRn4BxO4VQ==