Skip to content

Commit 0e319d4

Browse files
committed
introduce commonjs build
1 parent 2a95601 commit 0e319d4

12 files changed

+52
-26
lines changed

build/dev.config.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const buble = require('rollup-plugin-buble')
2+
const flow = require('rollup-plugin-flow-no-whitespace')
3+
const cjs = require('rollup-plugin-commonjs')
4+
const node = require('rollup-plugin-node-resolve')
5+
const replace = require('rollup-plugin-replace')
6+
7+
module.exports = {
8+
entry: 'src/index.js',
9+
dest: 'dist/vue-router.js',
10+
format: 'umd',
11+
moduleName: 'VueRouter',
12+
plugins: [replace({
13+
'process.env.NODE_ENV': '"development"'
14+
}), flow(), node(), cjs(), buble()]
15+
}

docs/en/installation.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
### Direct Download / CDN
44

5-
[https://unpkg.com/vue-router](https://unpkg.com/vue-router)
5+
[https://unpkg.com/vue-router/dist/vue-router.js](https://unpkg.com/vue-router/dist/vue-router.js)
66

77
<!--email_off-->
8-
[Unpkg.com](https://unpkg.com) provides NPM-based CDN links. The above link will always point to the latest release on NPM. You can also use a specific version/tag via URLs like `https://unpkg.com/[email protected]`.
8+
[Unpkg.com](https://unpkg.com) provides NPM-based CDN links. The above link will always point to the latest release on NPM. You can also use a specific version/tag via URLs like `https://unpkg.com/[email protected]/dist/vue-router.js`.
99
<!--/email_off-->
1010

1111
Include `vue-router` after Vue and it will install itself automatically:

docs/ja/installation.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
### 直接ダウンロード / CDN
44

5-
[https://unpkg.com/vue-router](https://unpkg.com/vue-router)
5+
[https://unpkg.com/vue-router/dist/vue-router.js](https://unpkg.com/vue-router/dist/vue-router.js)
66

77
<!--email_off-->
8-
[Unpkg.com](https://unpkg.com) は NPM ベースの CDN リンクです。 上記のリンクは常に NPM 上の最新のリリースを指します。 `https://unpkg.com/[email protected]` のような URL を利用することで特定のバージョンやタグを指定することもできます。
8+
[Unpkg.com](https://unpkg.com) は NPM ベースの CDN リンクです。 上記のリンクは常に NPM 上の最新のリリースを指します。 `https://unpkg.com/[email protected]/dist/vue-router.js` のような URL を利用することで特定のバージョンやタグを指定することもできます。
99
<!--/email_off-->
1010

1111
Vue の後に `vue-router` を含めると自動的にインストールされます。

docs/zh-cn/installation.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
### 直接下载 / CDN
44

5-
[https://unpkg.com/vue-router](https://unpkg.com/vue-router)
5+
[https://unpkg.com/vue-router/dist/vue-router.js](https://unpkg.com/vue-router/dist/vue-router.js)
66

77
<!--email_off-->
8-
[Unpkg.com](https://unpkg.com) 提供了基于 NPM 的 CDN 链接。上面的链接会一直指向在 NPM 发布的最新版本。你也可以像 `https://unpkg.com/[email protected]` 这样指定 版本号 或者 Tag。
8+
[Unpkg.com](https://unpkg.com) 提供了基于 NPM 的 CDN 链接。上面的链接会一直指向在 NPM 发布的最新版本。你也可以像 `https://unpkg.com/[email protected]/dist/vue-router.js` 这样指定 版本号 或者 Tag。
99
<!--/email_off-->
1010

1111
在 Vue 后面加载 `vue-router`,它会自动安装的:

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
"description": "Official router for Vue.js 2.0",
55
"author": "Evan You",
66
"license": "MIT",
7-
"main": "dist/vue-router.js",
7+
"main": "dist/vue-router.common.js",
88
"typings": "types/index.d.ts",
99
"files": [
1010
"dist/vue-router.js",
1111
"dist/vue-router.min.js",
12+
"dist/vue-router.common.js",
1213
"src",
1314
"types/index.d.ts",
1415
"types/router.d.ts",
@@ -21,7 +22,7 @@
2122
],
2223
"scripts": {
2324
"dev": "node examples/server.js",
24-
"dev:dist": "rollup -wm -c build/rollup.config.js",
25+
"dev:dist": "rollup -wm -c build/dev.config.js",
2526
"build": "node build/build.js",
2627
"lint": "eslint src examples",
2728
"test": "npm run lint && flow check && npm run test:unit && npm run test:e2e && npm run test:types",

src/create-matcher.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ export function createMatcher (routes: Array<RouteConfig>): Matcher {
6666
}
6767

6868
if (!redirect || typeof redirect !== 'object') {
69-
warn(false, `invalid redirect option: ${JSON.stringify(redirect)}`)
69+
process.env.NODE_ENV !== 'production' && warn(
70+
false, `invalid redirect option: ${JSON.stringify(redirect)}`
71+
)
7072
return _createRoute(null, location)
7173
}
7274

@@ -80,7 +82,9 @@ export function createMatcher (routes: Array<RouteConfig>): Matcher {
8082
if (name) {
8183
// resolved named direct
8284
const targetRecord = nameMap[name]
83-
assert(targetRecord, `redirect failed: named route "${name}" not found.`)
85+
if (process.env.NODE_ENV !== 'production') {
86+
assert(targetRecord, `redirect failed: named route "${name}" not found.`)
87+
}
8488
return match({
8589
_normalized: true,
8690
name,

src/create-route-map.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ function addRouteRecord (
2828
matchAs?: string
2929
) {
3030
const { path, name } = route
31-
assert(path != null, `"path" is required in a route configuration.`)
32-
assert(
33-
typeof route.component !== 'string',
34-
`route config "component" for path: ${String(path || name)} cannot be a ` +
35-
`string id. Use an actual component instead.`
36-
)
31+
if (process.env.NODE_ENV !== 'production') {
32+
assert(path != null, `"path" is required in a route configuration.`)
33+
assert(
34+
typeof route.component !== 'string',
35+
`route config "component" for path: ${String(path || name)} cannot be a ` +
36+
`string id. Use an actual component instead.`
37+
)
38+
}
3739

3840
const record: RouteRecord = {
3941
path: normalizePath(path, parent),
@@ -80,7 +82,7 @@ function addRouteRecord (
8082
if (name) {
8183
if (!nameMap[name]) {
8284
nameMap[name] = record
83-
} else {
85+
} else if (process.env.NODE_ENV !== 'production') {
8486
warn(false, `Duplicate named routes definition: { name: "${name}", path: "${record.path}" }`)
8587
}
8688
}

src/history/html5.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ export class HTML5History extends History {
7474
if (!behavior) {
7575
return
7676
}
77-
assert(typeof behavior === 'function', `scrollBehavior must be a function`)
77+
if (process.env.NODE_ENV !== 'production') {
78+
assert(typeof behavior === 'function', `scrollBehavior must be a function`)
79+
}
7880

7981
// wait until re-render finishes before scrolling
8082
router.app.$nextTick(() => {

src/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default class VueRouter {
5050
this.history = new AbstractHistory(this)
5151
break
5252
default:
53-
assert(false, `invalid mode: ${mode}`)
53+
process.env.NODE_ENV !== 'production' && assert(false, `invalid mode: ${mode}`)
5454
}
5555
}
5656

@@ -59,7 +59,7 @@ export default class VueRouter {
5959
}
6060

6161
init (app: any /* Vue component instance */) {
62-
assert(
62+
process.env.NODE_ENV !== 'production' && assert(
6363
install.installed,
6464
`not installed. Make sure to call \`Vue.use(VueRouter)\` ` +
6565
`before creating root instance.`

src/util/location.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { parsePath, resolvePath } from './path'
44
import { resolveQuery } from './query'
55
import { fillParams } from './params'
6-
import { assert } from './warn'
6+
import { warn } from './warn'
77

88
export function normalizeLocation (
99
raw: RawLocation,
@@ -27,8 +27,8 @@ export function normalizeLocation (
2727
} else if (current.matched) {
2828
const rawPath = current.matched[current.matched.length - 1].path
2929
next.path = fillParams(rawPath, params, `path ${current.path}`)
30-
} else {
31-
assert(false, `relative params navigation requires a current route.`)
30+
} else if (process.env.NODE_ENV !== 'production') {
31+
warn(false, `relative params navigation requires a current route.`)
3232
}
3333
return next
3434
}

src/util/params.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* @flow */
22

33
import Regexp from 'path-to-regexp'
4-
import { assert } from './warn'
4+
import { warn } from './warn'
55

66
const regexpCache: {
77
[key: string]: {
@@ -41,7 +41,9 @@ export function fillParams (
4141
(regexpCompileCache[path] = Regexp.compile(path))
4242
return filler(params || {}, { pretty: true })
4343
} catch (e) {
44-
assert(false, `missing param for ${routeMsg}: ${e.message}`)
44+
if (process.env.NODE_ENV !== 'production') {
45+
warn(false, `missing param for ${routeMsg}: ${e.message}`)
46+
}
4547
return ''
4648
}
4749
}

src/util/query.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function resolveQuery (
1414
try {
1515
parsedQuery = parseQuery(query)
1616
} catch (e) {
17-
warn(false, e.message)
17+
process.env.NODE_ENV !== 'production' && warn(false, e.message)
1818
parsedQuery = {}
1919
}
2020
for (const key in extraQuery) {

0 commit comments

Comments
 (0)