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/'

原文地址:https://www.cnblogs.com/fewhj/p/11978773.html