Skip to content

Commit 2dc2d06

Browse files
committed
adjust build
1 parent f242e11 commit 2dc2d06

File tree

24 files changed

+150
-131
lines changed

24 files changed

+150
-131
lines changed

benchmarks/ssr/renderToStream.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const Vue = require('../../dist/vue.common.js')
3+
const Vue = require('../../dist/vue.runtime.common.js')
44
const createRenderer = require('../../packages/vue-server-renderer').createRenderer
55
const renderToStream = createRenderer().renderToStream
66
const gridComponent = require('./common.js')

benchmarks/ssr/renderToString.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const Vue = require('../../dist/vue.common.js')
3+
const Vue = require('../../dist/vue.runtime.common.js')
44
const createRenderer = require('../../packages/vue-server-renderer').createRenderer
55
const renderToString = createRenderer().renderToString
66
const gridComponent = require('./common.js')

build/build.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,35 +69,32 @@ function buildEntry (config) {
6969
pure_funcs: ['makeMap']
7070
}
7171
}).code
72-
return write(config.dest, minified).then(zip(config.dest))
72+
return write(config.dest, minified, true)
7373
} else {
7474
return write(config.dest, code)
7575
}
7676
})
7777
}
7878

79-
function write (dest, code) {
80-
return new Promise(function (resolve, reject) {
81-
fs.writeFile(dest, code, function (err) {
82-
if (err) return reject(err)
83-
console.log(blue(path.relative(process.cwd(), dest)) + ' ' + getSize(code))
79+
function write (dest, code, zip) {
80+
return new Promise((resolve, reject) => {
81+
function report (extra) {
82+
console.log(blue(path.relative(process.cwd(), dest)) + ' ' + getSize(code) + (extra || ''))
8483
resolve()
85-
})
86-
})
87-
}
84+
}
8885

89-
function zip (file) {
90-
return function () {
91-
return new Promise(function (resolve, reject) {
92-
fs.readFile(file, function (err, buf) {
93-
if (err) return reject(err)
94-
zlib.gzip(buf, function (err, buf) {
86+
fs.writeFile(dest, code, err => {
87+
if (err) return reject(err)
88+
if (zip) {
89+
zlib.gzip(code, (err, zipped) => {
9590
if (err) return reject(err)
96-
write(file + '.gz', buf).then(resolve)
91+
report(' (gzipped: ' + getSize(zipped) + ')')
9792
})
98-
})
93+
} else {
94+
report()
95+
}
9996
})
100-
}
97+
})
10198
}
10299

103100
function getSize (code) {

build/config.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,47 @@ const banner =
1414

1515
const builds = {
1616
// Runtime only (CommonJS). Used by bundlers e.g. Webpack & Browserify
17-
'web-runtime-dev': {
17+
'web-runtime-cjs': {
1818
entry: path.resolve(__dirname, '../src/entries/web-runtime.js'),
19+
dest: path.resolve(__dirname, '../dist/vue.runtime.common.js'),
20+
format: 'cjs',
21+
banner
22+
},
23+
// Runtime+compiler CommonJS build (CommonJS)
24+
'web-full-cjs': {
25+
entry: path.resolve(__dirname, '../src/entries/web-runtime-with-compiler.js'),
1926
dest: path.resolve(__dirname, '../dist/vue.common.js'),
2027
format: 'cjs',
28+
alias: { he: './entity-decoder' },
2129
banner
2230
},
23-
// runtime-only build for CDN
24-
'web-runtime-cdn-dev': {
31+
// runtime-only build (Browser)
32+
'web-runtime-dev': {
2533
entry: path.resolve(__dirname, '../src/entries/web-runtime.js'),
2634
dest: path.resolve(__dirname, '../dist/vue.runtime.js'),
2735
format: 'umd',
2836
env: 'development',
2937
banner
3038
},
31-
// runtime-only production build for CDN
32-
'web-runtime-cdn-prod': {
39+
// runtime-only production build (Browser)
40+
'web-runtime-prod': {
3341
entry: path.resolve(__dirname, '../src/entries/web-runtime.js'),
3442
dest: path.resolve(__dirname, '../dist/vue.runtime.min.js'),
3543
format: 'umd',
3644
env: 'production',
3745
banner
3846
},
39-
// Runtime+compiler standalone development build.
40-
'web-standalone-dev': {
47+
// Runtime+compiler development build (Browser)
48+
'web-full-dev': {
4149
entry: path.resolve(__dirname, '../src/entries/web-runtime-with-compiler.js'),
4250
dest: path.resolve(__dirname, '../dist/vue.js'),
4351
format: 'umd',
4452
env: 'development',
4553
alias: { he: './entity-decoder' },
4654
banner
4755
},
48-
// Runtime+compiler standalone production build.
49-
'web-standalone-prod': {
56+
// Runtime+compiler production build (Browser)
57+
'web-full-prod': {
5058
entry: path.resolve(__dirname, '../src/entries/web-runtime-with-compiler.js'),
5159
dest: path.resolve(__dirname, '../dist/vue.min.js'),
5260
format: 'umd',
@@ -100,8 +108,7 @@ function genConfig (opts) {
100108

101109
if (opts.env) {
102110
config.plugins.push(replace({
103-
'process.env.NODE_ENV': JSON.stringify(opts.env),
104-
'process.env.VUE_ENV': JSON.stringify('client')
111+
'process.env.NODE_ENV': JSON.stringify(opts.env)
105112
}))
106113
}
107114

dist/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
## Explanation of Build Files
2+
3+
- ### vue.js
4+
5+
The full (compiler-included) browser build. This is the build you can just include with a script tag:
6+
7+
```
8+
<script src="https://unkpg.com/vue/dist/vue.js"><script>
9+
```
10+
11+
Note that this build is hard-coded to development mode.
12+
13+
- ### vue.min.js
14+
15+
Same as `vue.js`, but minified AND is hard-coded to production mode (with runtime checks and warnings stripped).
16+
17+
- ### vue.common.js
18+
19+
The full (compiler-included) CommonJS build. This is the build intended to be used with a Node-compatible bundler, e.g. Webpack or Browserify.
20+
21+
The difference between the browser build and the CommonJS build is that the latter preserves the `process.env.NODE_ENV` check for development/production modes (defaults to development mode). This gives you more control over what mode the code should run in:
22+
23+
- When bundling for the browser, you can turn on production mode by using Webpack's [DefinePlugin](https://webpack.github.io/docs/list-of-plugins.html#defineplugin) or Browserify's [envify](https://github.com/hughsk/envify) to replace `process.env.NODE_ENV` with the `"production"` string literal. This also allows minifiers to completely drop the warnings inside the conditional blocks. See [examples](http://vuejs.org/v2/guide/deployment.html).
24+
25+
- When running Vue in Node.js (during server side rendering), Vue will pick up the actual `process.env.NODE_ENV` if set.
26+
27+
- ### vue.runtime.common.js
28+
29+
The runtime-only (compiler-excluded) CommonJS build. **This is the default build you get from `import Vue from 'vue'` or `var Vue = require('vue')`**.
30+
31+
This build does not support the `template` option, because it doesn't include the compiler. It is thus 30% lighter than the full build. However, you can still use templates in Single-File `*.vue` components via `vue-loader` or `vueify`, as these tools will pre-compile the templates into render functions for you.
32+
33+
- ### vue.runtime.js
34+
35+
The runtime-only (compiler-excluded) browser build. You can also include this build with a script tag, but with this build, you will **not** be able to use the `template` option. Hard-coded to development mode.
36+
37+
- ### vue.runtime.min.js
38+
39+
Same as `vue.runtime.js`, but minified AND hard-coded to production mode (with runtime checks and warnings stripped).

flow/compiler.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
declare type CompilerOptions = {
22
warn?: Function; // allow customizing warning in different environments; e.g. node
3-
isIE?: boolean; // for detecting IE SVG innerHTML bug
43
expectHTML?: boolean; // only false for non-web builds
54
modules?: Array<ModuleOptions>; // platform specific modules; e.g. style; class
65
staticKeys?: string; // a list of AST properties to be considered static; for optimization

package.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
"name": "vue",
33
"version": "2.0.8",
44
"description": "Reactive, component-oriented view layer for modern web interfaces.",
5-
"main": "dist/vue.common.js",
5+
"main": "dist/vue.runtime.common.js",
66
"typings": "types/index.d.ts",
77
"files": [
8-
"dist/vue.common.js",
9-
"dist/vue.runtime.js",
10-
"dist/vue.runtime.min.js",
118
"dist/vue.js",
129
"dist/vue.min.js",
10+
"dist/vue.runtime.js",
11+
"dist/vue.runtime.min.js",
12+
"dist/vue.common.js",
13+
"dist/vue.runtime.common.js",
1314
"src",
1415
"types/index.d.ts",
1516
"types/options.d.ts",
@@ -18,28 +19,28 @@
1819
"types/vue.d.ts"
1920
],
2021
"scripts": {
21-
"dev": "TARGET=web-standalone-dev rollup -w -c build/config.js",
22-
"dev:runtime": "TARGET=web-runtime-dev rollup -w -c build/config.js",
22+
"dev": "TARGET=web-full-dev rollup -w -c build/config.js",
23+
"dev:cjs": "TARGET=web-runtime-cjs rollup -w -c build/config.js",
2324
"dev:test": "karma start build/karma.dev.config.js",
2425
"dev:ssr": "TARGET=web-server-renderer rollup -w -c build/config.js",
2526
"dev:compiler": "TARGET=web-compiler rollup -w -c build/config.js",
2627
"dev:weex": "TARGET=weex-framework rollup -w -c build/config.js",
2728
"dev:weex:compiler": "TARGET=weex-compiler rollup -w -c build/config.js",
2829
"build": "node build/build.js",
29-
"build:ssr": "npm run build -- vue.common.js,vue-server-renderer",
30+
"build:ssr": "npm run build -- vue.runtime.common.js,vue-server-renderer",
3031
"build:weex": "npm run build -- weex-vue-framework,weex-template-compiler",
3132
"test": "npm run lint && flow check && npm run test:types && npm run test:cover && npm run test:e2e -- --env phantomjs && npm run test:ssr",
3233
"test:unit": "karma start build/karma.unit.config.js",
3334
"test:cover": "karma start build/karma.cover.config.js",
3435
"test:e2e": "npm run build -- vue.min.js && node test/e2e/runner.js",
3536
"test:weex": "npm run build:weex && jasmine JASMINE_CONFIG_PATH=test/weex/jasmine.json",
36-
"test:ssr": "npm run build:ssr && VUE_ENV=server jasmine JASMINE_CONFIG_PATH=test/ssr/jasmine.json",
37+
"test:ssr": "npm run build:ssr && jasmine JASMINE_CONFIG_PATH=test/ssr/jasmine.json",
3738
"test:sauce": "npm run sauce -- 0 && npm run sauce -- 1 && npm run sauce -- 2",
3839
"test:types": "tsc -p ./types/test/tsconfig.json",
3940
"lint": "eslint src build test",
4041
"flow": "flow check",
4142
"sauce": "SAUCE=true karma start build/karma.sauce.config.js",
42-
"bench:ssr": "npm run build:ssr && NODE_ENV=production VUE_ENV=server node benchmarks/ssr/renderToString.js && NODE_ENV=production VUE_ENV=server node benchmarks/ssr/renderToStream.js",
43+
"bench:ssr": "npm run build:ssr && NODE_ENV=production node benchmarks/ssr/renderToString.js && NODE_ENV=production VUE_ENV=server node benchmarks/ssr/renderToStream.js",
4344
"release": "bash build/release.sh",
4445
"release:weex": "bash build/release-weex.sh"
4546
},

src/compiler/parser/index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { decode } from 'he'
44
import { parseHTML } from './html-parser'
55
import { parseText } from './text-parser'
66
import { cached, no, camelize } from 'shared/util'
7+
import { isIE, isServerRendering } from 'core/util/env'
78
import {
89
pluckModuleFunction,
910
getAndRemoveAttr,
@@ -69,23 +70,23 @@ export function parse (
6970

7071
// handle IE svg bug
7172
/* istanbul ignore if */
72-
if (options.isIE && ns === 'svg') {
73+
if (isIE && ns === 'svg') {
7374
attrs = guardIESVGBug(attrs)
7475
}
7576

7677
const element: ASTElement = {
7778
type: 1,
7879
tag,
7980
attrsList: attrs,
80-
attrsMap: makeAttrsMap(attrs, options.isIE),
81+
attrsMap: makeAttrsMap(attrs),
8182
parent: currentParent,
8283
children: []
8384
}
8485
if (ns) {
8586
element.ns = ns
8687
}
8788

88-
if (process.env.VUE_ENV !== 'server' && isForbiddenTag(element)) {
89+
if (isForbiddenTag(element) && !isServerRendering()) {
8990
element.forbidden = true
9091
process.env.NODE_ENV !== 'production' && warn(
9192
'Templates should only be responsible for mapping the state to the ' +
@@ -213,7 +214,7 @@ export function parse (
213214
}
214215
// IE textarea placeholder bug
215216
/* istanbul ignore if */
216-
if (options.isIE &&
217+
if (isIE &&
217218
currentParent.tag === 'textarea' &&
218219
currentParent.attrsMap.placeholder === text) {
219220
return
@@ -437,7 +438,7 @@ function parseModifiers (name: string): Object | void {
437438
}
438439
}
439440

440-
function makeAttrsMap (attrs: Array<Object>, isIE: ?boolean): Object {
441+
function makeAttrsMap (attrs: Array<Object>): Object {
441442
const map = {}
442443
for (let i = 0, l = attrs.length; i < l; i++) {
443444
if (process.env.NODE_ENV !== 'production' && map[attrs[i].name] && !isIE) {

src/core/config.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export type Config = {
1919
_assetTypes: Array<string>;
2020
_lifecycleHooks: Array<string>;
2121
_maxUpdateCount: number;
22-
_isServer: boolean;
2322
}
2423

2524
const config: Config = {
@@ -104,12 +103,7 @@ const config: Config = {
104103
/**
105104
* Max circular updates allowed in a scheduler flush cycle.
106105
*/
107-
_maxUpdateCount: 100,
108-
109-
/**
110-
* Server rendering?
111-
*/
112-
_isServer: process.env.VUE_ENV === 'server'
106+
_maxUpdateCount: 100
113107
}
114108

115109
export default config

src/core/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import config from './config'
2-
import { initGlobalAPI } from './global-api/index'
31
import Vue from './instance/index'
2+
import { initGlobalAPI } from './global-api/index'
3+
import { isServerRendering } from 'core/util/env'
44

55
initGlobalAPI(Vue)
66

77
Object.defineProperty(Vue.prototype, '$isServer', {
8-
get: () => config._isServer
8+
get: isServerRendering
99
})
1010

1111
Vue.version = '2.0.8'

src/core/instance/render.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import config from '../config'
44
import VNode, { emptyVNode, cloneVNode, cloneVNodes } from '../vdom/vnode'
55
import { normalizeChildren } from '../vdom/helpers/index'
66
import {
7-
warn, formatComponentName, bind, isObject, toObject,
7+
warn, formatComponentName, bind, isObject, toObject, isServerRendering,
88
nextTick, resolveAsset, _toString, toNumber, looseEqual, looseIndexOf
99
} from '../util/index'
1010

@@ -62,7 +62,7 @@ export function renderMixin (Vue: Class<Component>) {
6262
if (config.errorHandler) {
6363
config.errorHandler.call(null, e, vm)
6464
} else {
65-
if (config._isServer) {
65+
if (isServerRendering()) {
6666
throw e
6767
} else {
6868
console.error(e)

src/core/observer/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* @flow */
22

3-
import config from '../config'
43
import Dep from './dep'
54
import { arrayMethods } from './array'
65
import {
@@ -9,7 +8,8 @@ import {
98
isPlainObject,
109
hasProto,
1110
hasOwn,
12-
warn
11+
warn,
12+
isServerRendering
1313
} from '../util/index'
1414

1515
const arrayKeys = Object.getOwnPropertyNames(arrayMethods)
@@ -113,7 +113,7 @@ export function observe (value: any): Observer | void {
113113
ob = value.__ob__
114114
} else if (
115115
observerState.shouldConvert &&
116-
!config._isServer &&
116+
!isServerRendering() &&
117117
(Array.isArray(value) || isPlainObject(value)) &&
118118
Object.isExtensible(value) &&
119119
!value._isVue

src/core/util/env.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ export const isEdge = UA && UA.indexOf('edge/') > 0
1818
export const isAndroid = UA && UA.indexOf('android') > 0
1919
export const isIOS = UA && /iphone|ipad|ipod|ios/.test(UA)
2020

21+
// this needs to be lazy-evaled because vue may be required before
22+
// vue-server-renderer can set VUE_ENV
23+
let _isServer
24+
export const isServerRendering = () => {
25+
if (_isServer === undefined) {
26+
/* istanbul ignore if */
27+
if (!inBrowser && typeof global !== 'undefined') {
28+
// detect presence of vue-server-renderer and avoid
29+
// Webpack shimming the process
30+
_isServer = global['process'].env.VUE_ENV === 'server'
31+
} else {
32+
_isServer = false
33+
}
34+
}
35+
return _isServer
36+
}
37+
2138
// detect devtools
2239
export const devtools = inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__
2340

0 commit comments

Comments
 (0)