-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add recipe for precompiling source files with webpack #1212
Changes from 5 commits
e7d028b
72220e4
4fe6197
b5513b1
f259de2
ea49034
07d098a
cd67d1c
919e123
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. | ||
|
||
###### webpack.config.js | ||
|
||
```js | ||
const nodeExternals = require('webpack-node-externals'); | ||
|
||
module.exports = { | ||
entry: ['src/tests.js'], | ||
target: 'node', | ||
output: { | ||
path: '_build', | ||
filename: 'tests.js' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As someone who didn't know about this feature, I'm asking questions from a first time user standpoint that I think are important to address:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a file with the contents of all the transpiled test code and all of its dependencies. It's really ugly and wouldn't really help to see. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The The |
||
}, | ||
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 libraries which it may choke on. | ||
|
||
You can now run `$ ava _build/tests.js` to run the tests contained in this output. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a link to this recipe in the AVA readme at https://github.com/avajs/ava#transpiling-imported-modules