Skip to content

一个域名下部署一个项目(默认打包后的结构)

dist css img js favicon.ico index.html

js
module.exports = {
  // 用来指定 index.html 中自动引入的 js、css 文件的路径前缀,默认为 /
  publicPath: '/',
  // 打包在哪个文件夹下,默认为 dist
  outputDir: 'dist',
  // 静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录,默认为 ''
  assetsDir: '',
}

如果想将静态资源放入 dist/assets 中,只需要配置 assetsDir 为 'assets' 即可,同时 index.html 会自动将路径前缀修改为 /assets/css/...

js
module.exports = {
  outputDir: 'dist',
  assetsDir: 'assets',
}

一个域名下部署多个项目。

dist foo css img js favicon.ico index.html bar css img js favicon.ico index.html

一个域名下部署多个项目,其中一个部署在子路径 foo,通过 https://www.app.com/foo/ 访问, 打包时只需要将 outputDir 配置为 'dist/foo' 即可。

js
module.exports = {
  outputDir: 'dist/foo',
}

如果想将静态资源放入 dist/assets 中,只需要配置 assetsDir 为 'assets' 即可,同时 index.html 会自动将路径前缀修改为 /assets/css/...

js
module.exports = {
  outputDir: 'dist/foo',
  assetsDir: 'assets',
}