Skip to content

Commit

Permalink
feat: add WEBPACK_PACKAGE env var to use custom webpack package (#…
Browse files Browse the repository at this point in the history
…2556)

* feat: add `WEBPACK_PACKAGE` env variable

* fix: typo
  • Loading branch information
snitin315 committed Mar 26, 2021
1 parent d039472 commit 3d1e485
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/webpack-cli/lib/webpack-cli.js
Expand Up @@ -9,7 +9,7 @@ const utils = require('./utils');
class WebpackCLI {
constructor() {
// Global
this.webpack = require('webpack');
this.webpack = require(process.env.WEBPACK_PACKAGE || 'webpack');
this.logger = utils.logger;
this.utils = utils;

Expand Down
1 change: 1 addition & 0 deletions test/build/custom-webpack/custom-webpack.js
@@ -0,0 +1 @@
module.exports = require('webpack');
26 changes: 26 additions & 0 deletions test/build/custom-webpack/custom-webpack.test.js
@@ -0,0 +1,26 @@
'use strict';

const { resolve } = require('path');
const { run } = require('../../utils/test-utils');

describe('custom-webpack', () => {
it('should use custom-webpack.js', () => {
const { exitCode, stderr, stdout } = run(__dirname, [], {
env: { WEBPACK_PACKAGE: resolve(__dirname, './custom-webpack.js') },
});

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toContain('main.js');
});

it('should throw an error for invalid-webpack.js', () => {
const { exitCode, stderr, stdout } = run(__dirname, [], {
env: { WEBPACK_PACKAGE: resolve(__dirname, './invalid-webpack.js') },
});

expect(exitCode).toBe(2);
expect(stderr).toContain(`Error: Cannot find module`);
expect(stdout).toBeFalsy();
});
});
1 change: 1 addition & 0 deletions test/build/custom-webpack/src/index.js
@@ -0,0 +1 @@
console.log('hi');
3 changes: 3 additions & 0 deletions test/build/custom-webpack/webpack.config.js
@@ -0,0 +1,3 @@
module.exports = {
mode: 'production',
};

0 comments on commit 3d1e485

Please sign in to comment.