-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add recipe for precompiling source files with webpack (#1212)
- Loading branch information
1 parent
3279336
commit a49f66b
Showing
2 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
## Precompiling source files with webpack | ||
|
||
The AVA [readme](https://github.com/avajs/ava#transpiling-imported-modules) mentions precompiling your imported modules as an alternative to runtime compilation, but it doesn't explain how. This recipe shows how to do this using webpack. (This example uses webpack 2.0) | ||
|
||
###### webpack.config.js | ||
|
||
```js | ||
const nodeExternals = require('webpack-node-externals'); | ||
|
||
module.exports = { | ||
entry: ['src/tests.js'], | ||
target: 'node', | ||
output: { | ||
path: '_build', | ||
filename: 'tests.js' | ||
}, | ||
externals: nodeExternals, | ||
module: { | ||
rules: [{ | ||
test: /\.(js|jsx)$/, | ||
use: 'babel-loader' | ||
}] | ||
} | ||
}; | ||
``` | ||
|
||
The important bits are `target: 'node'`, which ignores Node.js-specific `require`s (e.g. `fs`, `path`, etc.) and `externals: nodeModules` which prevents webpack from trying to bundle external Node.js modules which it may choke on. | ||
|
||
You can now run `$ ava _build/tests.js` to run the tests contained in this output. |
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