Business background
< hr >- use
mpvue
to develop Mini Program - the domain names of the test environment and the formal environment are different, so the images returned by the server are all relative paths
- the way it is handled now is
- configure a global domain name prefix
- add this global prefix to the image after each request API gets the data
- after changing the formal environment, you only need to replace the global domain name prefix
sample code
< hr >conifg.js
export default {
url: "http://test.com"
}
page .js
request()
.then(res => {
res.img = config.url + res.img;
})
perplexed
< hr > handle the prefix every time you request
feel particularly troublesome
explore
< hr > learn that publicpath
in output
of webpack
can add prefixes to static resources in batches, but it doesn"t reflect
webpack.config.js
output: {
path: config.build.assetsRoot,
filename: "[name].js",
publicPath: "https://img.codeshelper.com/upload/img/2021/03/21/tsifcahkcnd11661.png">
render result
<image class="_img data-v-04ee3f7a" src="uploads/2010-06-19/3.png"></image>
it seems that there is no processing when packing.
question
- Why isn"t
publicpath
added to the picture path whenwebpack
is packaged? - is there any way to add prefixes automatically?