Gibt es derzeit eine Möglichkeit, während der Verwendung der API node.js auf den Fortschritt des Webpacks zuzugreifen? Ich kenne den --progress -Flag mit dem CLI.Webpack-Fortschritt mit node.js-API
23
A
Antwort
26
Die Webpack CLI verwendet den ProgressPlugin, um den Fortschritt einer Kompilierung zu protokollieren.
var ProgressPlugin = require('webpack/lib/ProgressPlugin');
var compiler = webpack(config);
compiler.apply(new ProgressPlugin(function(percentage, msg) {
console.log((percentage * 100) + '%', msg);
}));
compiler.run(function(err, stats) {
// ...
});
Hier ist ein Link auf die Compiler documentation und der ProgressPlugin documentation.
3
https://www.npmjs.com/package/progress-bar-webpack-plugin Dieses Plugin nutzt den Knoten-Fortschritt.
new ProgressBarPlugin({
format: ' build [:bar] :percent (:elapsed seconds)',
clear: false,
width: 60
})
6
Zur Ausgabe etwas ähnliches wie die CLI --progress
Flag:
var webpack = require('webpack')
var ProgressPlugin = require('webpack/lib/ProgressPlugin')
var config = require('./webpack.config')
var compiler = webpack(config)
compiler.apply(new ProgressPlugin(function (percentage, msg, current, active, modulepath) {
if (process.stdout.isTTY && percentage < 1) {
process.stdout.cursorTo(0)
modulepath = modulepath ? ' …' + modulepath.substr(modulepath.length - 30) : ''
current = current ? ' ' + current : ''
active = active ? ' ' + active : ''
process.stdout.write((percentage * 100).toFixed(0) + '% ' + msg + current + active + modulepath + ' ')
process.stdout.clearLine(1)
} else if (percentage === 1) {
process.stdout.write('\n')
console.log('webpack: done.')
}
}))
compiler.run(function (err, stats) {
if (err) throw err
process.stdout.write(stats.toString({
colors: true,
modules: false,
children: false,
chunks: false,
chunkModules: false
}) + '\n\n')
})
+1
das ist großartig, danke. – heisian
Verwandte Themen
- 1. Mit zwei Befehlen (Rohr mit |) mit Laich
- 2. Umgang mit Daten mit MVC mit AngularJS
- 3. mit Deklaration mit enum?
- 4. Mit jQuery mit DevExpress
- 5. Mit NodeJS mit Typoskript
- 6. Mit MaterializeCSS mit Aurelia
- 7. mit ffmpeg mit Xcode
- 8. Mit AngularJS mit MeteorJS
- 9. mit Arrays.sort mit Lambda
- 10. Mit OpenBLAS mit GSL
- 11. mit DBMS_APPLICATION_INFO mit Jboss
- 12. Mit MvxCommand Mit Command
- 13. Mit Supercollider mit Python
- 14. Mit forever.js mit Python
- 15. Mit GraphiQL mit Foxx
- 16. Mit Moles mit System.Reflection
- 17. Probleme mit jQuery Mit
- 18. Mit Parsec mit data.text
- 19. Mit Repo mit msysGit
- 20. Mit html2Canvas mit HighCharts
- 21. Mit javac mit Import
- 22. mit KeyStore mit .crt
- 23. Mit DevicIOControl mit VC#
- 24. mit Python mit bash
- 25. mit pushstate mit Slashes
- 26. Mit mkl_set_num_threads mit numpy
- 27. mit Atom.io mit winscp
- 28. Mit scala.sys.process mit Timeout
- 29. mit jQuery mit socket.io
- 30. Mit Reflection mit Android
Pair dieser mit [node-progress] (https://github.com/tj/node-progress) für formatieren Konsolenausgabe. –
Liste aller internen Webpack-Plugins: https://github.com/webpack/docs/wiki/internal-webpack-plugins –