Webpack output.publicpath does not work

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

after trying.
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 when webpack is packaged?
  • is there any way to add prefixes automatically?
Mar.21,2021

https://webpack.js.org/config. 's official website makes it very clear


publicPath is added to distinguish the path between the server and the client, and to distinguish the files to be processed

clipboard.png

clipboard.png

you can better view

in the browser.
  • Webpack4 build failed

    build the mpvue project according to http: mpvue.com mpvue -sharp_3. The error is as follows: function generateLoaders (loader, loaderOptions) in unitls.js { var ExtractTextPlugin = require( extract-text-webpack-plugin ) var MiniCssExtractPlu...

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b359d9-2bfa4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b359d9-2bfa4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?