Skip to content
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

Merged
merged 9 commits into from
Mar 11, 2017
Merged

Add recipe for precompiling source files with webpack #1212

merged 9 commits into from
Mar 11, 2017

Conversation

danny-andrews
Copy link
Contributor

Fixes #1011.

path: '_build',
filename: 'tests.js'
},
externals: nodeModules,
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@sindresorhus
Copy link
Member

Is this Webpack v1 or v2? I think it should be Webpack v2 and be specified as such.

@sindresorhus sindresorhus changed the title precompiling-with-webpack.md Add recipe for precompiling source files with webpack Jan 28, 2017
@sindresorhus
Copy link
Member

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.
Copy link
Member

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

@sindresorhus
Copy link
Member

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_build

@sindresorhus
Copy link
Member

ping @danny-andrews

@danny-andrews
Copy link
Contributor Author

Added the fixes you requested. @sindresorhus

@sindresorhus
Copy link
Member

Is this Webpack v1 or v2? I think it should be Webpack v2 and be specified as such.

@danny-andrews ⬆️

@sindresorhus
Copy link
Member

@TheLarkInn Could you take a look?

target: 'node',
output: {
path: '_build',
filename: 'tests.js'

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?

Copy link
Contributor Author

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.

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.

@TheLarkInn
Copy link

Thanks for the ping @sindresorhus 🐱 🐕 🐓 🚀. Was surprised I didn't know this feature existed!! MFW:
68a971d3c92e870fe4beed5a3f8d71a9

@danny-andrews
Copy link
Contributor Author

@sindresorhus Anything else you'd like me to add?

@sindresorhus sindresorhus merged commit a49f66b into avajs:master Mar 11, 2017
@sindresorhus
Copy link
Member

@danny-andrews Good stuff. Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants