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

feat: add WEBPACK_PACKAGE env var to use custom webpack package #2556

Merged
merged 2 commits into from Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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',
};