Last active
June 25, 2021 00:09
-
-
Save fivethreeo/0e2c6a467b6e1236b862082a317ca938 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const WebpackLastFilesLoggerPlugin = require('./WebpackLastFilesLoggerPlugin'); | |
module.exports = { | |
modifyWebpackConfig({ // note Config not Options | |
env: { | |
target, // the target 'node' or 'web' | |
dev, // is this a development build? true or false | |
}, | |
webpackConfig, // the created webpack config | |
webpackObject, // the imported webpack node module | |
options: { | |
razzleOptions, // the modified options passed to Razzle in the `options` key in `razzle.config.js` (options: { key: 'value'}) | |
webpackOptions, // the modified options that will be used to configure webpack/ webpack loaders and plugins | |
}, | |
paths, // the modified paths that will be used by Razzle. | |
}) { | |
webpackConfig.plugins.push(new WebpackLastFilesLoggerPlugin()); | |
return webpackConfig; | |
}, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
// https://github.com/storybookjs/storybook/issues/14342 | |
// https://webpack.js.org/contribute/plugin-patterns/#monitoring-the-watch-graph | |
/** | |
* Logs the last changed files during webpack rebuilds. | |
*/ | |
class WebpackLastFilesLoggerPlugin { | |
constructor() { | |
this.startTime = Date.now(); | |
this.prevTimestamps = new Map(); | |
} | |
apply(compiler) { | |
compiler.hooks.emit.tapAsync('MyPlugin', (compilation, callback) => { | |
const changedFiles = Array.from(compilation.fileTimestamps.keys()).filter((watchfile) => { | |
return ((this.prevTimestamps.get(watchfile) || this.startTime) < | |
(compilation.fileTimestamps.get(watchfile) || Infinity)); | |
}); | |
if (changedFiles.length) { | |
console.log(` | |
The following files changed since last build: | |
${changedFiles.map((file) => `- ${file}`).join('\n')} | |
`); | |
} | |
this.prevTimestamps = compilation.fileTimestamps; | |
callback(); | |
}); | |
} | |
} | |
module.exports = WebpackLastFilesLoggerPlugin; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment