简单配置
最简单地修改webpack的配置方式是在你的 saber-node.js 中,使用 getWebpackConfig 钩子,像这样:
exports.getWebpackConfig = function(config, { type }) {
// e.g. Adding a webpack plugin
config.plugins.push(new SomeWebpackPlugin())
// `type` is either `client` or `server`
if (type === 'client') {
config.plugins.push(new SomeWebpackPluginForClientBuild())
}
// You must return the `config`!
return config
}
高级配置
使用 webpack-chain
在 saber-node.js 中使用 chainWebpack 钩子 去接入 webpack-chain 实例:
exports.chainWebpack = function(chain) {
// e.g. Resolve .css files
chain.resolve.extensions.add('.css')
}
部署
使用命令 saber build 创建一个公共的目录以及你的程序的生产环境。设置你最喜欢的HTTP服务器去准确地服务静态 .html文件和其他静态资料。
内置静态服务
通过使用 saber serve 命令,它可以自动地服务 public 目录:
cd my-site
yarn saber build
yarn saber serve
这对于预览本地生产环境很好。
其它解决方法
去开启Saber应用程序,你不一定非得需要内置的静态服务,它可以在大多静态服务器上运行,例如,你可以使用 sirv-cli:
npx sirv-cli public
或:
npx serve public
Building for Relative Paths
默认情况下,Saber会假设你的应用托管在服务器根目录下生成构建。要覆盖此内容,请指定在你的Saber配置文件中的build.publicUrl,例如:
// saber.config.js
module.exports = {
build: {
publicUrl: '/blog/'
}
}