With Webpack, is it possible to generate CSS only, excluding the output.js?

前端 未结 4 969
春和景丽
春和景丽 2021-01-30 11:25

I\'m using Webpack with the extract-text-webpack-plugin.

In my project, I have some build scripts. One of the build scripts is supposed to bundle and minify CSS only. As

4条回答
  •  走了就别回头了
    2021-01-30 11:33

    One solution is to execute webpack with the Node API and control the output with the memory-fs option. Just tell it to ignore the resulting js-file. Set the output.path to "/" in webpackConfig.

    var compiler = webpack(webpackConfig);
    var mfs = new MemoryFS();
    compiler.outputFileSystem = mfs;
    compiler.run(function(err, stats) {
        if(stats.hasErrors()) { throw(stats.toString()); }
        mfs.readdirSync("/").forEach(function (f) {
            if(f === ("app.js")) { return; } // ignore js-file
            fs.writeFileSync(destination + f, mfs.readFileSync("/" + f));
        })
    });
    

提交回复
热议问题