当我运行 npm run build
时,我在使用相对路径进行正确构建时遇到了困难。解析资产很容易,但我不知道如何配置两件事:
1/ assetsPublicPath
在 config/index.js
// see http://vuejs-templates.github.io/webpack for documentation.
var path = require('path')
module.exports = {
build: {
env: require('./prod.env'),
index: path.resolve(__dirname, '../dist/index.html'),
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: '/ONLY_ABSOLUTE_PATH_ARE_ALLOWED/',
productionSourceMap: true,
// Gzip off by default as many popular static hosts such as
// Surge or Netlify already gzip all static assets for you.
// Before setting to `true`, make sure to:
// npm install --save-dev compression-webpack-plugin
productionGzip: false,
productionGzipExtensions: ['js', 'css']
},
dev: {
env: require('./dev.env'),
port: 8080,
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {},
// CSS Sourcemaps off by default because relative paths are "buggy"
// with this option, according to the CSS-Loader README
// (https://github.com/webpack/css-loader#sourcemaps)
// In our experience, they generally work as expected,
// just be aware of this issue when enabling this option.
cssSourceMap: false
}
}
2/ vue-router
配置中的 base
选项似乎也只接受绝对路径…
const router = new VueRouter({
mode: 'history',
base: '/ABSOLUTE_PATH_ONLY/',
routes: [
{ path: '/', redirect: '/fr/poster/home' },
{ path: '/:lang', redirect: '/:lang/poster/home' },
{
path: '/:lang/poster',
component: PosterLayout,
children: [
{
// UserProfile will be rendered inside User's <router-view>
// when /user/:id/profile is matched
name: 'home',
path: 'home',
component: Home
},
{
// UserPosts will be rendered inside User's <router-view>
// when /user/:id/posts is matched
name: 'themeCover',
path: ':theme',
component: ThemeCover
}
]
},
{
name: 'themeDetails',
path: '/:lang/theme/:theme',
component: ThemeDetails
}
]
})
因此,当我指定正确的未来 URL 时它可以工作,但它不是“未来证明”,以防服务器被修改……
如果可以解决,有什么想法可以解决这个问题吗?
原文由 Existe Deja 发布,翻译遵循 CC BY-SA 4.0 许可协议
我知道从你写这篇文章开始一切都变了。但是此时使用最新版本的 Vue 和 Vue Cli,您可以通过 vue 配置文件获得它(我不是这个平台的专家):
在项目的主路径创建一个“vue.config.js”文件
给出一个相对路径。例子:
它不适用于在 css 中添加的字体,我不知道为什么,我仍在谷歌搜索。如果有人阅读可以提供帮助,那就太好了。