Skip to content

Commit

Permalink
feat: upgrade nuxt.js to next before 1.0.0 released
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkdo committed Dec 10, 2017
1 parent 000f56f commit e15d4b1
Show file tree
Hide file tree
Showing 10 changed files with 704 additions and 990 deletions.
3 changes: 3 additions & 0 deletions client/assets/styles/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ header,
// max-height: 900px;
margin: 0 auto;
}
#__layout{
height: 100%;
}
body {
font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB',
'Microsoft YaHei', SimSun, sans-serif;
Expand Down
6 changes: 3 additions & 3 deletions client/middleware/check-auth.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { user as getUser } from '@/utils/auth'

export default function ({ isServer, store, req, route, redirect }) {
export default function ({ store, req, route, redirect }) {
// If nuxt generate, pass this middleware
if (isServer && !req) return
const user = getUser(isServer ? req : null)
if (process.static) return
const user = getUser(process.server ? req : null)
if (user && !store.state.authUser) {
store.commit('SET_USER', user)
} else if (!user && route.name !== 'login') {
Expand Down
10 changes: 5 additions & 5 deletions client/pages/examples/activity/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<el-table-column prop="account" :label="$t('activity.account')" width="120" sortable>
</el-table-column>
<el-table-column :label="$t('activity.date')" width="120" sortable>
<template scope="scope">{{ scope.row.date }}</template>
<template slot-scope="scope">{{ scope.row.date }}</template>
</el-table-column>
<el-table-column prop="type" :label="$t('activity.type')" width="120" sortable>
</el-table-column>
Expand All @@ -35,7 +35,7 @@
<el-table-column type="selection" width="55">
</el-table-column>
<el-table-column type="expand">
<template scope="props">
<template slot-scope="props">
<el-form label-position="left" inline class="demo-table-expand">
<el-form-item :label="$t('activity.area')+':'">
<span>{{ props.row.region }}</span>
Expand All @@ -55,15 +55,15 @@
<el-table-column prop="account" :label="$t('activity.account')">
</el-table-column>
<el-table-column :label="$t('activity.date')">
<template scope="scope">{{ scope.row.date }}</template>
<template slot-scope="scope">{{ scope.row.date }}</template>
</el-table-column>
<el-table-column
prop="type"
:label="$t('activity.type')"
:filters="[{ text: '优惠', value: '价格优惠' }, { text: '权限', value: '价格权益' }]"
:filter-method="filterTag"
filter-placement="bottom-end">
<template scope="tag">
<template slot-scope="tag">
<el-tag
:type="tag.row.type === '价格优惠' ? 'primary' : 'success'"
close-transition>{{tag.row.type}}</el-tag>
Expand All @@ -90,7 +90,7 @@ import Component from 'class-component'
export default class Example extends Vue {
selections = []
async asyncData ({ isServer }) {
async asyncData () {
let {data: activities} = await axios.get('/hpi/activities')
return {activities}
}
Expand Down
4 changes: 2 additions & 2 deletions client/pages/examples/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@
</el-input>
</el-col>
<el-col :offset="2" :span="6" :xs="22">
<el-input :placeholder="$t('example.inPh')" v-model="restaurant">
<!-- <el-input :placeholder="$t('example.inPh')" v-model="restaurant">
<el-select class="input-sel" v-model="restOptions" slot="prepend" :placeholder="$t('example.selPh')">
<el-option label="餐厅名" value="1"></el-option>
<el-option label="订单号" value="2"></el-option>
<el-option label="用户电话" value="3"></el-option>
</el-select>
<el-button slot="append" icon="search"></el-button>
</el-input>
</el-input> -->
</el-col>
<el-col :offset="2" :span="6" :xs="22">
<el-select v-model="multiFood" multiple :placeholder="$t('example.selPh')">
Expand Down
10 changes: 4 additions & 6 deletions client/plugins/axios-defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { defaultHeader, clientToken } from '@/utils/auth'

const PORT = process.env.PORT || '3000'

export default ({ req, isServer, redirect }) => {
if (!isServer) {
export default ({ req, redirect }) => {
if (process.client) {
defaultHeader(clientToken())
axios.interceptors.response.use(
response => response,
Expand All @@ -19,10 +19,8 @@ export default ({ req, isServer, redirect }) => {
return Promise.reject(error)
}
)
}
axios.defaults.timeout = 5000
// for generate
if (isServer && !req) {
} else {
axios.defaults.baseURL = `http://127.0.0.1:${PORT}`
}
axios.defaults.timeout = 5000
}
4 changes: 2 additions & 2 deletions client/plugins/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import Negotiator from 'negotiator'

Vue.use(VueI18n)

export default ({ app, store, isServer, req }) => {
if (isServer && req) {
export default ({ app, store, req }) => {
if (process.server) {
const negotiator = new Negotiator(req)
const lang = negotiator.language(store.state.locales)
store.commit('SET_LANG', lang || 'zh')
Expand Down
2 changes: 1 addition & 1 deletion nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {
babel: {
plugins: ['transform-decorators-legacy', 'transform-class-properties']
},
extend (config, { dev, isClient }) {
extend (config, { isDev }) {
config.resolve.alias['class-component'] = '@/plugins/class-component'
},
vendor: [
Expand Down
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
"bunyan": "^1.8.12",
"chart.js": "^2.7.1",
"cross-env": "^5.1.0",
"element-ui": "^1.4.8",
"element-ui": "^1.4.12",
"js-cookie": "^2.2.0",
"js-yaml": "^3.9.1",
"jwt-decode": "^2.2.0",
"koa": "^2.4.1",
"koa-body": "^2.3.0",
"koa-bunyan": "^1.0.0",
"koa-bunyan": "^1.0.1",
"koa-bunyan-logger": "^2.0.0",
"koa-compose": "^4.0.0",
"koa-compress": "^2.0.0",
Expand All @@ -59,13 +59,13 @@
"moment": "^2.19.2",
"negotiator": "^0.6.1",
"normalize.css": "^7.0.0",
"nuxt": "^1.0.0-rc11",
"nuxt": "^1.0.0-gh-0b9cd1b",
"svg-captcha": "^1.3.11",
"vue-chartjs": "^3.0.2",
"vue-class-component": "^5.0.1",
"vue-class-component": "^6.1.1",
"vue-clipboards": "^1.2.0",
"vue-i18n": "^7.3.2",
"vuex-class": "^0.2.0",
"vuex-class": "^0.3.0",
"xmlify": "^1.1.0"
},
"devDependencies": {
Expand All @@ -77,7 +77,8 @@
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"eslint": "^4.12.0",
"babel-plugin-transform-runtime": "^6.23.0",
"eslint": "^4.13.0",
"eslint-config-standard": "^10.2.1",
"eslint-plugin-html": "^4.0.1",
"eslint-plugin-import": "^2.8.0",
Expand All @@ -88,16 +89,16 @@
"lint-staged": "^5.0.0",
"moxios": "^0.4.0",
"node-sass": "^4.7.2",
"nodemon": "^1.11.0",
"nodemon": "^1.12.5",
"progress-bar-webpack-plugin": "^1.10.0",
"sass-loader": "^6.0.6",
"standard-version": "^4.2.0",
"uglifyjs-webpack-plugin": "^1.1.1",
"webpack": "^3.5.5",
"webpack": "^3.10.0",
"webpack-node-externals": "^1.6.0"
},
"engines": {
"node": ">=7.6.0",
"npm": ">=4.0.0"
"node": ">=8.0.0",
"npm": ">=5.0.0"
}
}
11 changes: 3 additions & 8 deletions server/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Koa from 'koa'
import { Nuxt, Builder } from 'nuxt'
import axios from 'axios'
import bunyan from 'bunyan'
import mkdirp from 'mkdirp'
import koaBunyan from 'koa-bunyan'
Expand All @@ -27,8 +26,6 @@ async function start () {

app.keys = ['hare-server']
config.dev = !(app.env === 'production')
axios.defaults.baseURL = `http://127.0.0.1:${port}`

// logging
let logDir = process.env.LOG_DIR || (isWin ? 'C:\\\\log' : '/var/tmp/log')
mkdirp.sync(logDir)
Expand Down Expand Up @@ -68,11 +65,6 @@ async function start () {
})

const nuxt = new Nuxt(config)
nuxt.showOpen = () => {
const _host = host === '0.0.0.0' ? 'localhost' : host
// eslint-disable-next-line no-console
console.log('\n' + chalk.bgGreen.black(' OPEN ') + chalk.green(` http://${_host}:${port}\n`))
}
// Build only in dev mode
if (config.dev) {
const devConfigs = config.development
Expand Down Expand Up @@ -141,6 +133,9 @@ async function start () {
})

app.listen(port, host)
const _host = host === '0.0.0.0' ? 'localhost' : host
// eslint-disable-next-line no-console
console.log('\n' + chalk.bgGreen.black(' OPEN ') + chalk.green(` http://${_host}:${port}\n`))
}

start()
Loading

0 comments on commit e15d4b1

Please sign in to comment.