U
U
undefined2020-08-27 18:04:16
JavaScript
undefined, 2020-08-27 18:04:16

How to dynamically change paths to JS files in JSON file in Vue Cli?

I have a project on Vue Cli 4, the project has a JSON file, this file has paths to JS files, that is, the essence is simple, this file goes through the GenerateJsonFileWepbackPlugin and goes to dist/ when building the project, but the problem is that this the file has paths to JS files that are in dist, that is, I can write the paths to these files manually, but I have to rewrite them every time, it seems not scary, but these files have a hash, that is, name.7e9572v.js change it dynamically, and each time it is somehow time-consuming to write, and so, the essence of the question is whether it is possible somehow at the JSON processing level through the GenerateJsonFileWepbackPlugin to live out the path to the updated JS file names there.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2020-08-27
@Aetae

Write your plugin, there is nothing complicated:

class RandomPlugin {
  apply(compiler) {
    compiler.hooks.emit.tapAsync(this.constructor.name, (compilation, callback) => {
      const chunkList = [];
      for (const chunk of compilation.chunks) {
        // тут какая-нить фильтрация
        chunkList.push(...chunk.files);
      }
      // тут запись в файл или ещё что
      console.log(chunkList);
      callback();
    });
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question