vue build默认打包的目录是dist 但是有时候我们不需要这样的结构目录 ,需要增加二级目录。
1.修改config=> index.js
const pathName = 'web-wechat'
build: {
index: path.resolve(__dirname, `../dist/${pathName}/index.html`),
assetsRoot: path.resolve(__dirname, `../dist/${pathName}`),
assetsSubDirectory: 'static',
assetsPublicPath: `/${pathName}/`,
productionSourceMap: false,
devtool: '#source-map',
productionGzip: true,
productionGzipExtensions: ['js', 'css'],
bundleAnalyzerReport: process.env.npm_config_report
}
这样访问的时候,就会出现指定的二级目录,如下:
虽然js、css、image的路径都正确,但是由于用了UI框架,里面引用的组件路径以及data中声明的路径并未正确。
我采取的解决方法(import方式):
import wealth from '../../static/images/caifu.png'