1

I wrote a plugin, mainly provide mock data for requests, since this part is purely standalone, so in entry file it's not imported, which means webpack can't track this mock data's change. So how to manually add this mock folder to webpack and make it can be watched during developing ? Thanks!

1 Answer 1

1

You can use extra-watch-webpack-plugin in order to add an additional files / dirs to webpack watch.

Or you can implement a similar thing that it implemented.

compiler.hooks.afterCompile.tap('after-compile', compilation => {
    // for adding a specific file
    fileDependencies.forEach(file => {
      compilation.fileDependencies.add(resolve(file));
    });

    // for adding a dir
    dirDependencies.forEach(dir => {
      compilation.contextDependencies.add(dir);
    });
});

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks for the reply but I did this already, sorry that I didn't post it. The question I got is how to get its latest data. For example, I have a mock file named person.json, and I request via http in main.js(entry file), I update this json file, the app updated but this request still get the old version of data, which I'm trying to solve.
sounds like a browser cache, not related to webpack... add a random (new Date().getTime()) querystring the request...
no, it's not, I even refreshed the page and data is still old, only way to fetch the latest one is to restart project. I think I must've miss some part but just can't think of any.
Ha, is this file is required by node? if so, nodes require has a caching mechnizem built in... You will need to bust it before re-require it... delete require.cache[require.resolve(module)]; require(module)
Ah YES! I didn't even think of this could be the one ! Problem solved! Thanks !
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.