Vue-cli 3.0 package how to add version numbers to js and css, and how to change the names of js and css

vue-cli 3.0 packages how to add version numbers to js and css, and how to change the names of js and css.

Jul.08,2022

create the file vue.config.js in the root directory of the project, and then configure the corresponding packaged output in the file, as follows:

clipboard.png

const path = require("path");
const systemConfig = require("./src/lib/system.config");   //
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
module.exports = {
  configureWebpack: {
    output: {
      //      .
      filename: `js/[name].${systemConfig.version}.js`,
      chunkFilename: `js/[name].${systemConfig.version}.js`
    },
    plugins: [
      new MiniCssExtractPlugin({
        // css
        filename: `css/[name].${systemConfig.version}.css`,
        chunkFilename: `css/[name].${systemConfig.version}.css`
      })
    ]
  },
  // img
  chainWebpack: config => {
    config.module
      .rule("images")
      .use("url-loader")
      .tap(options => {
        options.name = `img/[name].${systemConfig.version}.[ext]`;
        options.fallback = {
          loader: "file-loader",
          options: {
            name: `img/[name].${systemConfig.version}.[ext]`
          }
        };
        return options;
      });
  },
 
};

const Timestamp = new Date (). GetTime (); / / timestamp
module.exports = {
configureWebpack: {/ / webpack configuration

output: { //      ..
  filename: `[name].${process.env.VUE_APP_Version}.${Timestamp}.js`,
  chunkFilename: `[name].${process.env.VUE_APP_Version}.${Timestamp}.js`
},

},
...
}

Menu