vue-cli中 assetsPublicPath, assetsSubDirectory的区别


webpack配置代码:

index: path.resolve(__dirname, '../dist/index.html'),
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: './projectName' // 相对路径

上述代码的含义:

assetsRoot : 在当前目录的上一级 的 dist目录下输出资源文件

assetsSubDirectory: 把所有的静态资源打包到 dist下的 static文件夹下

assetsPublicPath :代表生成的index.html文件,里面引入资源时,路径前面要加上 ./projectName/,也就是assetsPublicPath的值,即在index.html代码中引用静态文件:

<script type="text/javascript" src="./projectName/static/js/app.js"></script>

如果要是把资源放在https://www.baidu.com/projectName目录下面,可以这样配置

assetsPublicPath: './'

如果使用的是histroy 模式,使用相对路径报错,可以这样配置成绝对路径

assetsPublicPath: '/projectName/'


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM