search

Home  >  Q&A  >  body text

node.js - 如何在webpack构建完成后执行我的一些nodejs代码

webpack有类似如下的api吗

webpack.on("after-emit",function(){
  //我的代码
  //...
});

在webpack构建完成后,我需要执行一些移动文件的操作,将源码中指定的文件移动到生成的文件夹中,请问应该怎么做?

迷茫迷茫2907 days ago537

reply all(2)I'll reply

  • ringa_lee

    ringa_lee2017-04-17 15:04:30

    You can use npm scripts, npm run webpack && npm run copy

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 15:04:30

    webpack itself provides Node.js api, which can be started in a script:

    var webpack = require("webpack");
    
    // returns a Compiler instance
    webpack({
        // configuration
    }, function(err, stats) {
        // ...
    });

    Then you can move on to other things

    So you can write the startup of webpack and other required operations in the same script, and then run the script directly in the console

    reply
    0
  • Cancelreply