webpack-fixture
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

webpack-fixture

The fixture is needed to create webpack compilation tests.

The result of the function execution returns:

  • compiler This instance can be used to manually trigger the webpack runner or have it build and watch for changes

  • volume is an instance of Volume constructor, it is the default volume created for your convenience

  • fs is an fs-like object created from vol using createFsFromVolume(vol)

Usage

import webpack from 'webpack';
import webpackFixture from 'webpack-fixture';

const webpackConfig:webpack.Configuration  = {
  entry: '/index.js',
  mode: 'production',
  output: {
    filename: 'bundle.js',
    path: '/build',
  },
};

const { compiler, fs, volume } = webpackFixture(webpackConfig);
fs.writeFileSync('/index.js', `
console.log(1)
const _ = 1;
console.log(2)
`);

const { err, stats } = await new Promise((resolve) => {
  compiler.run((err, stats) => {
    resolve({ err, stats });
  });
});

const volumeJon = volume.toJSON();

/*
volumeJon['/index.js'] => `
console.log(1)
const _ = 1;
console.log(2)
`

volumeJon['/build/bundle.js'] => `console.log(1),console.log(2);`
*/

Package Sidebar

Install

npm i webpack-fixture

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

4.18 kB

Total Files

5

Last publish

Collaborators

  • pan-alexey