Geo*_*bol 9 webpack vue.js vue-router vuejs2
当我跑步时,我正面临着使用相对路径进行正确构建的困难npm run build.解决资产很容易,但我不知道如何配置2件事:
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
}
}
Run Code Online (Sandbox Code Playgroud)
2/配置中的base选项vue-router似乎也只接受绝对路径......
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
}
]
})
Run Code Online (Sandbox Code Playgroud)
因此,当我指定正确的未来URL时,它可以正常工作,但它不是"未来证明",以防服务器被修改...
如果它可以解决,任何想法来解决这个问题?
J.S*_*nio 17
我知道你写完这篇文章的一切都有所改变.但是目前使用Vue和Vue Cli的最后一个版本你可以使用vue配置文件获取它(我不是这个平台的专家):
在项目的主路径中创建"vue.config.js"文件
给出相对路径.例:
module.exports = {
publicPath: './'
};
Run Code Online (Sandbox Code Playgroud)
它不适用于在CSS中添加的字体,我不知道为什么,我仍然在googlying.如果有人阅读可以帮助将是伟大的.
我已经通过以下vue.config.js设置解决了我的问题:
module.exports = {
publicPath: process.env.BASE_URL,
assetsDir: process.env.BASE_URL
};
Run Code Online (Sandbox Code Playgroud)
webpack.config.js我认为你也可以通过改变来做到同样的事情output.publicPath。参考:https://cli.vuejs.org/guide/html-and-static-assets.html#url-transform-rules
你也可以做publicPath: process.env.BASE_URL + '/static/'
绝对路径不必包含域名,只需从根开始即可。
考虑一下 HTML5 URL。例如,如果您的静态文件夹位于http://www.example.com/static且当前 url 为,http://www.example.com/users则相对路径将为../static。但是,如果您尝试查看用户的详细信息并转到http://www.example.com/users/john-doe,则相对路径将为../../static。如果您不知道资产在哪里,则无法加载它们,这就是为什么您需要一个起点,一个绝对 URL。
你害怕什么问题?你可以说得更详细点吗?
| 归档时间: |
|
| 查看次数: |
9976 次 |
| 最近记录: |