Last active
February 1, 2016 18:45
-
-
Save roobie/4fa82c757d5ef013ba81 to your computer and use it in GitHub Desktop.
a webpack plugin that is used to enable continuous testing via webpack compilation
This file contains hidden or 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
| /* | |
| The following packages are required (other versions may work) | |
| "tap-spec": "^4.1.1", | |
| "lodash": "^4.1.0", | |
| -- | |
| minimal webpack config: | |
| ``` | |
| module.exports = { | |
| target: 'node', | |
| entry: './test/index.js', | |
| output: { | |
| path: 'output', | |
| filename: 'test.js' | |
| }, | |
| plugins: [ | |
| new TapSpecWebpackPlugin() | |
| ] | |
| } | |
| ``` | |
| */ | |
| var tapSpec = require('tap-spec'); | |
| var spawn = require('child_process').spawn; | |
| var _ = require('lodash'); | |
| module.exports = TapSpecWebpackPlugin; | |
| function TapSpecWebpackPlugin() { }; | |
| TapSpecWebpackPlugin.prototype.apply = function (compiler) { | |
| compiler.plugin('after-emit', emitted); | |
| function emitted(compilation, callback) { | |
| var source = _(compilation.chunks) | |
| .filter('entry') | |
| .map(function (c) { | |
| return c.files[0]; | |
| }) | |
| .map(function (f) { | |
| return compilation.assets[f]; | |
| }) | |
| .map(function (a) { | |
| return a.source(); | |
| }).valueOf().join('\n;'); | |
| var proc = spawn(process.execPath, { | |
| stdio: ['pipe', 'pipe', 'inherit'] | |
| }); | |
| proc.stdout.pipe(tapSpec()) | |
| .pipe(process.stdout); | |
| proc.stdin.end(source, 'utf8'); | |
| proc.on('exit', exited); | |
| function exited(code) { | |
| return callback(); | |
| } | |
| } | |
| }; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment