事实证明,解决方案非常简单。你所需要做的就是使用它
compliation.assets
fs.writeFile
. 无论您是从内存还是从文件系统提供文件,这都将起作用。
例如,下面的代码将在中创建一个文件
path/to/file.ext
具有
Hello World!
class MyCoolPlugin {
apply(compiler) {
compiler.hooks.emit.tapAsync('MyCoolPlugin', (compilation, done) => {
compilation.assets['path/to/file.ext'] = {
source: () => 'Hello World!', // The file's content
size: () => 10 // Should be the byte size of the content
};
done();
});
}
}