Skip to content

Commit

Permalink
support SSR
Browse files Browse the repository at this point in the history
  • Loading branch information
liuzhenangel committed Oct 19, 2016
1 parent a920a7e commit 127d723
Show file tree
Hide file tree
Showing 28 changed files with 384 additions and 511 deletions.
1 change: 1 addition & 0 deletions .ackrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--ignore-dir=dist
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,32 @@ vue-migration-helper src folder-a folder-b

![Screenshot](http://i.imgur.com/aHh5TfR.png)

## 支持服务端渲染

代码更改详情: <>

服务端渲染文档: <http://vuefe.cn/guide/ssr.html>

支持服务端渲染主要修改的是加一个中间件 `server.js`, 另外一个需要注意的地方是配置服务端渲染后 `vue-resource` 加载时会报一个 `document is not defined` 错误, 错误详情可以查看这个 [Issue](https://github.com/vuejs/vue-resource/issues/455), 处理这个问题的方法是:

把这两行代码


`import VueResource from 'vue-resource'`

`Vue.use(VueResource)`


改成下面的方式

`const inBrowser = typeof window !== 'undefined'`

`if (inBrowser) {`

`Vue.use(require('vue-resource'))`

`}`


## 项目介绍

Expand Down
35 changes: 0 additions & 35 deletions build/build.js

This file was deleted.

9 changes: 0 additions & 9 deletions build/dev-client.js

This file was deleted.

65 changes: 0 additions & 65 deletions build/dev-server.js

This file was deleted.

35 changes: 35 additions & 0 deletions build/setup-dev-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const path = require('path')
const webpack = require('webpack')
const MFS = require('memory-fs')
const clientConfig = require('./webpack.client.config')
const serverConfig = require('./webpack.server.config')

module.exports = function setupDevServer (app, onUpdate) {
clientConfig.entry.app = ['webpack-hot-middleware/client', clientConfig.entry.app]
clientConfig.plugins.push(
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
)

const clientCompiler = webpack(clientConfig)
app.use(require('webpack-dev-middleware')(clientCompiler, {
publicPath: clientConfig.output.publicPath,
stats: {
colors: true,
chunks: false
}
}))
app.use(require('webpack-hot-middleware')(clientCompiler))

const serverCompiler = webpack(serverConfig)
const mfs = new MFS()
const outputPath = path.join(serverConfig.output.path, serverConfig.output.filename)
serverCompiler.outputFileSystem = mfs
serverCompiler.watch({}, (err, stats) => {
if (err) throw err
stats = stats.toJson()
stats.errors.forEach(err => console.error(err))
stats.warnings.forEach(err => console.warn(err))
onUpdate(mfs.readFileSync(outputPath, 'utf-8'))
})
}
59 changes: 0 additions & 59 deletions build/utils.js

This file was deleted.

7 changes: 7 additions & 0 deletions build/vue-loader.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
postcss: [
require('autoprefixer')({
browsers: ['last 3 versions']
})
]
}
85 changes: 0 additions & 85 deletions build/webpack.base.conf.js

This file was deleted.

38 changes: 38 additions & 0 deletions build/webpack.base.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const path = require('path')
const webpack = require('webpack')
const vueConfig = require('./vue-loader.config')

module.exports = {
devtool: '#source-map',
entry: {
app: './src/client-entry.js',
vendor: ['vue', 'vue-router', 'lru-cache', 'es6-promise']
},
output: {
path: path.resolve(__dirname, '../dist'),
publicPath: '/dist/',
filename: 'client-bundle.js'
},
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue',
options: vueConfig
},
{
test: /\.js$/,
loader: 'babel',
exclude: /node_modules/
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'url',
options: {
limit: 10000,
name: '[name].[ext]?[hash]'
}
}
]
}
}
Loading

1 comment on commit 127d723

@bigzhu
Copy link

@bigzhu bigzhu commented on 127d723 Nov 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

似乎整个项目就变为只支持ssr的了,有没有能同时支持编译普通的vue项目和ssr的方案

Please sign in to comment.