Webpack4.x 解决本地和生产地址不一致,使用绝对地址
依赖关系:
"webpack": "^4.12.0",
"webpack-cli": "^3.0.3",
"vue": "^2.5.16",
"vue-loader": "^14.2.2",
Webpack配置output内容:参考
// :关键点: const publicPath = isProd ? '/vue/' : '/'; output: { path: path.resolve('dist' + publicPath), publicPath: publicPath, filename: `js/[name]${isProd ? '.[hash:7]' : ''}.js` }, // 关键点: 上面的publicPath相当于Webpack 的 DefinePlugin执行了↓ new webpack.DefinePlugin({ 'process.env.ASSET_PATH': JSON.stringify(extPath), }),
Vue组件A标签使用href路径:
// 测试环境路径为: /tools
// 生产环境路径为: /vue/tools
<a :href="`${__webpack_public_path__}tools/fifa`"> const link = `${__webpack_public_path__}tools/fifa`
相关推荐
不知道该写啥QAQ 2020-11-12
webfullStack 2020-11-09
Yvettre 2020-09-15
想做大牛的蜗牛 2020-10-30
gloria0 2020-10-26
gaojie0 2020-09-11
SelinaChan 2020-08-14
不知道该写啥QAQ 2020-08-09
gloria0 2020-08-09
不知道该写啥QAQ 2020-08-02
hline 2020-07-29
SelinaChan 2020-07-28
wangdianyong 2020-07-23
webpackvuees 2020-07-23
yqoxygen 2020-07-20
不知道该写啥QAQ 2020-07-18
waterv 2020-07-18
81463166 2020-07-17