Skip to content

Commit 961743c

Browse files
committed
build setup
1 parent cec5101 commit 961743c

9 files changed

+160
-7
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
.DS_Store
22
node_modules
33
test/test.build.js
4-
test/test.html
4+
test/test.html
5+
example/example.build.js
6+
TODOS.md

karma.conf.js renamed to build/karma.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = function (config) {
33
browsers: ['PhantomJS'],
44
reporters: ['progress'],
55
frameworks: ['jasmine'],
6-
files: ['test/test.build.js'],
6+
files: [__dirname + '/../test/test.build.js'],
77
singleRun: true
88
})
99
}

webpack.config.js renamed to build/webpack.build.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var webpack = require("webpack")
2-
var version = require('./package.json').version
2+
var version = require('../package.json').version
33
var banner =
44
'/**\n' +
55
' * vue-router v' + version + '\n' +

build/webpack.example.config.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
entry: './example/example.js',
3+
output: {
4+
path: './example',
5+
filename: 'example.build.js'
6+
}
7+
}
File renamed without changes.

example/example.js

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
var Vue = require('vue')
2+
var VueRouter = require('../src')
3+
4+
Vue.use(VueRouter)
5+
6+
var router = new VueRouter({
7+
pushstate: true,
8+
root: '/hello'
9+
})
10+
11+
var root = new Vue({
12+
el: '#app',
13+
components: {
14+
inbox: {
15+
template: '<div><h2>inbox!</h2><div v-view></div></div>',
16+
replace: true,
17+
components: {
18+
message: {
19+
template: '<div>message! {{route.params.messageId}}</div>',
20+
replace: true
21+
},
22+
archive: {
23+
template: '<div>archive lol</div>',
24+
replace: true
25+
}
26+
}
27+
},
28+
user: {
29+
template: '<h2>User yo</h2><div v-view></div>',
30+
components: {
31+
'user-profile': {
32+
template: 'user profile {{route.params.userId}} {{route.params.something}}'
33+
},
34+
'user-posts': {
35+
template: 'user posts'
36+
},
37+
'user-settings': {
38+
template: 'user settings'
39+
}
40+
}
41+
},
42+
about: {
43+
template: '<h1>OHHHH ABOUT</h1>',
44+
replace: true
45+
},
46+
'not-found': {
47+
template: 'FOUR OH FOUR'
48+
}
49+
}
50+
})
51+
52+
router.on('/inbox', {
53+
name: 'inbox',
54+
component: 'inbox',
55+
subRoutes: {
56+
'/message/:messageId': {
57+
name: 'message',
58+
component: 'message',
59+
alwaysRefresh: true
60+
},
61+
'/archived': {
62+
name: 'archive',
63+
component: 'archive'
64+
}
65+
}
66+
})
67+
68+
router.on('/user/:userId', {
69+
name: 'user',
70+
component: 'user',
71+
subRoutes: {
72+
'profile/:something': {
73+
component: 'user-profile'
74+
},
75+
'posts': {
76+
component: 'user-posts'
77+
},
78+
'settings': {
79+
component: 'user-settings'
80+
}
81+
}
82+
})
83+
84+
router.on('/about', {
85+
component: 'about',
86+
})
87+
88+
router.notfound({
89+
component: 'not-found'
90+
})
91+
92+
router.redirect({
93+
'/info': '/about'
94+
})
95+
96+
router.start(root)

example/index.html

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<style>
2+
.test {
3+
transition: all .5s ease;
4+
}
5+
.test-enter, .test-leave {
6+
opacity: 0;
7+
}
8+
</style>
9+
10+
<div id="app">
11+
<h1>App Header</h1>
12+
<a v-link="/inbox/message/123">inbox</a>
13+
<a v-link="/about">about</a>
14+
<a v-link="/user/1234">user</a>
15+
<div v-view class="test" v-transition="test" transition-mode="out-in"></div>
16+
</div>
17+
18+
<script src="example.build.js"></script>

example/serve.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var exec = require('child_process').exec
2+
var spawn = require('child_process').spawn
3+
var app = require('express')()
4+
5+
app.get('/example.build.js', function (req, res) {
6+
res.sendFile(__dirname + '/example.build.js')
7+
})
8+
9+
app.get('*', function (req, res) {
10+
res.sendFile(__dirname + '/index.html')
11+
})
12+
13+
app.listen(3000, function () {
14+
console.log('dev server running on localhost:3000\n')
15+
openURL('http://localhost:3000')
16+
})
17+
18+
function openURL (url) {
19+
switch (process.platform) {
20+
case "darwin":
21+
exec('open ' + url)
22+
break
23+
case "win32":
24+
exec('start ' + url)
25+
break
26+
default:
27+
spawn('xdg-open', [url])
28+
}
29+
}

package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"description": "A router for Vue.js",
55
"main": "src/index.js",
66
"scripts": {
7-
"dev": "webpack --watch",
8-
"build": "webpack",
9-
"test": "webpack --config webpack.test.config.js && ./node_modules/karma/bin/karma start"
7+
"dev": "node example/serve.js & webpack --watch --config build/webpack.example.config.js",
8+
"build": "webpack --config build/webpack.build.config.js",
9+
"test": "webpack --config build/webpack.test.config.js && ./node_modules/karma/bin/karma start build/karma.config.js"
1010
},
1111
"repository": {
1212
"type": "git",
@@ -25,11 +25,12 @@
2525
},
2626
"homepage": "https://github.com/vuejs/vue-router#readme",
2727
"devDependencies": {
28+
"express": "^4.12.3",
2829
"jasmine-core": "^2.3.2",
2930
"karma": "^0.12.31",
3031
"karma-jasmine": "^0.3.5",
3132
"karma-phantomjs-launcher": "^0.1.4",
32-
"vue": "^0.11.10",
33+
"vue": "yyx990803/vue#dev",
3334
"webpack": "^1.8.11"
3435
},
3536
"dependencies": {

0 commit comments

Comments
 (0)