Skip to content

Latest commit

 

History

History
31 lines (24 loc) · 1.05 KB

precompiling-with-webpack.md

File metadata and controls

31 lines (24 loc) · 1.05 KB

Precompiling source files with webpack

Translations: Français

The AVA readme 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
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 requires (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.