0

I have an Angular project (with a few lines of AssemblyScript) and i'm trying to make the WASM compilation and copy the compiled files into the assets folder juste before Angular re-builds the project when we make some changes.

I've tried to make use of the "Custom webpack builders" but even when i try to use the "BeforeCompile" hook from webpack, angular re-builds and re-builds... I think it's because it take X miliseconds to copy the files into the angular assets folder, and then it detects changes, then it rebuilds...

Do you have some idea?

Here's my custom webpack code:

const { exec } = require("child_process");
module.exports = {
watchOptions: {
    ignored: /node_modules/,
},
plugins: [
    {
        apply: (compiler) => {
            compiler.hooks.beforeCompile.tap('MyPlugin', () => {
                exec('npm run asbuild', (err, stdout, stderr) => {
                    console.error('stderr', stderr);
                    console.warn('stdout', stdout);
                });
            });
        },
    }
]

};

Ricardo Machado
  • 787
  • 1
  • 8
  • 16
  • Just an idea, but can you not (watch) ignore the assets folder (or a subfolder inside)? – MikeOne Jun 27 '22 at 18:22
  • I've not found how to ignore a specific assets file/folder. – Ricardo Machado Jun 27 '22 at 18:52
  • Try to use a different hook, like: compiler.hooks.thisCompilation.tap(pluginName, (compilation) => compilation.hooks.processAssets.tap( { name: pluginName, stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL, }, async (assets) => { } ) ); and make sure you always "await" Promise and async. – ThexBasic Aug 13 '23 at 20:41

0 Answers0