Skip to content

Commit 3d1e485

Browse files
authored
feat: add WEBPACK_PACKAGE env var to use custom webpack package (#2556)
* feat: add `WEBPACK_PACKAGE` env variable * fix: typo
1 parent d039472 commit 3d1e485

File tree

5 files changed

+32
-1
lines changed

5 files changed

+32
-1
lines changed

packages/webpack-cli/lib/webpack-cli.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const utils = require('./utils');
99
class WebpackCLI {
1010
constructor() {
1111
// Global
12-
this.webpack = require('webpack');
12+
this.webpack = require(process.env.WEBPACK_PACKAGE || 'webpack');
1313
this.logger = utils.logger;
1414
this.utils = utils;
1515

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('webpack');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
3+
const { resolve } = require('path');
4+
const { run } = require('../../utils/test-utils');
5+
6+
describe('custom-webpack', () => {
7+
it('should use custom-webpack.js', () => {
8+
const { exitCode, stderr, stdout } = run(__dirname, [], {
9+
env: { WEBPACK_PACKAGE: resolve(__dirname, './custom-webpack.js') },
10+
});
11+
12+
expect(exitCode).toBe(0);
13+
expect(stderr).toBeFalsy();
14+
expect(stdout).toContain('main.js');
15+
});
16+
17+
it('should throw an error for invalid-webpack.js', () => {
18+
const { exitCode, stderr, stdout } = run(__dirname, [], {
19+
env: { WEBPACK_PACKAGE: resolve(__dirname, './invalid-webpack.js') },
20+
});
21+
22+
expect(exitCode).toBe(2);
23+
expect(stderr).toContain(`Error: Cannot find module`);
24+
expect(stdout).toBeFalsy();
25+
});
26+
});
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('hi');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
mode: 'production',
3+
};

0 commit comments

Comments
 (0)