-
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
Conversation
path: '_build', | ||
filename: 'tests.js' | ||
}, | ||
externals: nodeModules, |
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.
I have not tested the recipe. But we should instead declare nodeExternals
instead of nodeModules
? I have a little difficulty understanding the logic. If what you wrote is correct then it might be good to explain why we should do this.
What do you think?
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.
No, that was just a typo. It's fixed now.
Is this Webpack v1 or v2? I think it should be Webpack v2 and be specified as such. |
Note that I added a commit to this PR: 4fe6197 |
@@ -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. |
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
You also need to add this to the recipes list: https://github.com/avajs/ava#recipes |
|
||
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 _buid/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.
_build
ping @danny-andrews |
Added the fixes you requested. @sindresorhus |
|
@TheLarkInn Could you take a look? |
target: 'node', | ||
output: { | ||
path: '_build', | ||
filename: 'tests.js' |
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.
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:
- I would love to see an example of what this file looks like. Could a code block be added above to show this? Is it just a list of
t.test
? Or better yet is there a repo for this?
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
The entry: ['src/tests.js']
can be a list of t.test
or, better yet, require
or import
statements pulling in the tests you want to run, because you probably don't want all your tests in one file, unless your project is tiny. As the name suggests, it's the entry point that Webpack will look at to determine what to compile.
The output.filename
will contain the compiled code.
Thanks for the ping @sindresorhus 🐱 🐕 🐓 🚀. Was surprised I didn't know this feature existed!! MFW: |
@sindresorhus Anything else you'd like me to add? |
@danny-andrews Good stuff. Thanks :) |
Fixes #1011.