关于vue打包的问题

一、vue-cli2
二、vue-cli3

一、vue-cli2
  1. 错误提示:
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! hewelry@1.0.0 build: node build/build.js
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the hewelry@1.0.0 build script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
    npm ERR! A complete log of this run can be found in:
    npm ERR! C:\Users\techsun\AppData\Roaming\npm-cache\_logs\2019-09-20T06_38_09_597Z-debug.log

完整错误信息:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
因为这个提示,找了一整天,结果是因为 标签没有闭合!!!,简直巨坑。

2. 关于图片资源路径
(1)现将 route.js 中的 mode:history 改成 mode:hash
在这里插入图片描述
(2) config 文件夹下的 index.js
在这里插入图片描述
3. 改了 assetsPublicPath 还是加载不出来,或者 index.html 不显示, 仍然报:Failed to load resource: net::ERR_FILE_NOT_FOUND。找到 build 文件夹
参考了这位老哥的分享:huang_jin_yi
(1)webpack.base.conf.js 文件在这里插入图片描述
(2)webpack.prod.conf.js 文件添加:publicPath:'./
在这里插入图片描述
4. 图片路径正确,但是背景图没有
参考了这位老哥的分享:小唛的前端宝库
build文件夹下 utils.js 文件下添加:publicPath:"../../"
在这里插入图片描述


一、vue-cli3

1. router.js 文件–>将 history 模式改成 hash 模式

const router = new VueRouter({
  // mode: 'history',
  mode: 'hash',
  base: process.env.BASE_URL,//根
  routes
})

2. 在项目根目录下 新增一个 vue.config.js 文件

module.exports = {
  publicPath : './',//打包时配置静态资源路径 打包要“./”
  // publicPath: '/tcEnterprise'
  // vue-cli3中baseUrl被废弃,用publicPath
  outputDir: 'tcTrace' // 打包后压缩包的名称
}

3. npm run build

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值