问题标签 [vue-loader]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1584 浏览

webpack - Vuejs webpack 前缀静态资源

您好,我使用了一个 Vuetify 应用程序vue-clivue init vuetifyjs/webpack-advanced生成的代码是这个https://github.com/vuetifyjs/webpack-advanced/tree/master/template

我遇到的问题是我的生产应用程序不在服务器的根目录中,它是www.example.com/foo. 当我运行npm run build我的所有静态资产(如图像和字体)时,它们被引用为/static/images/example.png,因此服务器在查找它们时找不到它们,www.example.com/static/images/example.png而不是www.example.com/foo/static/images/example.png

如果我更改config/index.js并设置assetsPublicPath: '/foo'和更改我的所有引用/static/.../foo/static/...那么我的生产服务器会找到我的所有静态资产,但是我的开发服务器使用npm run dev无法找到它们,因为它们被引用localhost:8080/foo/static/images/example.png但它们似乎 localhost:8080/static/images/example.png出于某种原因。

我理想的解决方案是将引用保持为 /static 并以某种方式告诉 webpack 或 vueloadernpm run build应该将 /foo 添加到我的所有资产中。如果这是不可能的,至少我想知道一种方法让我的开发和生产环境使用相同的代码,即使这意味着手动添加 /foo 到我的静态资产 url

谢谢

0 投票
0 回答
192 浏览

css - 如何输出单个 CSS 文件