From 7c6f390a1d64d562065ffc31d8b23d833813ee9d Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Wed, 7 Apr 2021 18:05:43 +0530 Subject: [PATCH] feat: added `--no-devtool` to webpack v4(#2603) --- packages/webpack-cli/lib/webpack-cli.js | 4 ++++ .../devtool/array/source-map-array.test.js | 6 ++++-- test/build/devtool/array/webpack.config.js | 4 ++++ .../devtool/object/source-map-object.test.js | 19 ++++++++++++++++--- .../devtool/object/webpack.eval.config.js | 3 +++ .../devtool/object/webpack.source.config.js | 3 +++ .../__snapshots__/help.test.js.snap.webpack4 | 8 ++++++++ 7 files changed, 42 insertions(+), 5 deletions(-) diff --git a/packages/webpack-cli/lib/webpack-cli.js b/packages/webpack-cli/lib/webpack-cli.js index 23177d515e6..d080c9b6595 100644 --- a/packages/webpack-cli/lib/webpack-cli.js +++ b/packages/webpack-cli/lib/webpack-cli.js @@ -515,6 +515,10 @@ class WebpackCLI { { type: 'string', }, + { + type: 'enum', + values: [false], + }, ], negative: true, alias: 'd', diff --git a/test/build/devtool/array/source-map-array.test.js b/test/build/devtool/array/source-map-array.test.js index 441fc66912f..d7585ae20d5 100644 --- a/test/build/devtool/array/source-map-array.test.js +++ b/test/build/devtool/array/source-map-array.test.js @@ -9,7 +9,9 @@ describe('source-map object', () => { expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); + // multi compilers + expect(stdout).toContain("devtool: 'source-map'"); + expect(stdout).toContain("devtool: 'eval-cheap-module-source-map'"); let files; @@ -27,7 +29,7 @@ describe('source-map object', () => { expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); + expect(stdout).toContain("devtool: 'source-map'"); let files; diff --git a/test/build/devtool/array/webpack.config.js b/test/build/devtool/array/webpack.config.js index e59ce251d17..b43cebaa257 100644 --- a/test/build/devtool/array/webpack.config.js +++ b/test/build/devtool/array/webpack.config.js @@ -1,3 +1,5 @@ +const WebpackCLITestPlugin = require('../../../utils/webpack-cli-test-plugin'); + module.exports = [ { output: { @@ -8,6 +10,7 @@ module.exports = [ entry: './index.js', mode: 'development', devtool: 'eval-cheap-module-source-map', + plugins: [new WebpackCLITestPlugin()], }, { output: { @@ -19,5 +22,6 @@ module.exports = [ mode: 'development', devtool: 'source-map', target: 'node', + plugins: [new WebpackCLITestPlugin()], }, ]; diff --git a/test/build/devtool/object/source-map-object.test.js b/test/build/devtool/object/source-map-object.test.js index f89652c6c90..9d8c79b9d54 100644 --- a/test/build/devtool/object/source-map-object.test.js +++ b/test/build/devtool/object/source-map-object.test.js @@ -9,7 +9,7 @@ describe('source-map object', () => { expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); + expect(stdout).toContain("devtool: 'eval-cheap-module-source-map'"); let files; @@ -27,7 +27,7 @@ describe('source-map object', () => { expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); + expect(stdout).toContain("devtool: 'source-map'"); expect(existsSync(resolve(__dirname, 'dist/dist-amd.js.map'))).toBeTruthy(); }); @@ -40,7 +40,20 @@ describe('source-map object', () => { expect(exitCode).toBe(0); expect(stderr).toBeFalsy(); - expect(stdout).toBeTruthy(); + expect(stdout).toContain("devtool: 'source-map'"); + expect(existsSync(resolve(__dirname, 'binary/dist-amd.js.map'))).toBeTruthy(); + }); + + it('should override config with devtool false', async () => { + const { exitCode, stderr, stdout } = await run( + __dirname, + ['-c', './webpack.eval.config.js', '--no-devtool', '-o', './binary'], + false, + ); + + expect(exitCode).toBe(0); + expect(stderr).toBeFalsy(); + expect(stdout).toContain('devtool: false'); expect(existsSync(resolve(__dirname, 'binary/dist-amd.js.map'))).toBeTruthy(); }); }); diff --git a/test/build/devtool/object/webpack.eval.config.js b/test/build/devtool/object/webpack.eval.config.js index ba392ae1c35..7c2bec6f0d6 100644 --- a/test/build/devtool/object/webpack.eval.config.js +++ b/test/build/devtool/object/webpack.eval.config.js @@ -1,3 +1,5 @@ +const WebpackCLITestPlugin = require('../../../utils/webpack-cli-test-plugin'); + module.exports = { output: { filename: './dist-amd.js', @@ -7,4 +9,5 @@ module.exports = { entry: './index.js', mode: 'development', devtool: 'eval-cheap-module-source-map', + plugins: [new WebpackCLITestPlugin()], }; diff --git a/test/build/devtool/object/webpack.source.config.js b/test/build/devtool/object/webpack.source.config.js index d4999a8ef78..efb87fa2f90 100644 --- a/test/build/devtool/object/webpack.source.config.js +++ b/test/build/devtool/object/webpack.source.config.js @@ -1,3 +1,5 @@ +const WebpackCLITestPlugin = require('../../../utils/webpack-cli-test-plugin'); + module.exports = { output: { filename: './dist-amd.js', @@ -7,4 +9,5 @@ module.exports = { entry: './index.js', mode: 'development', devtool: 'source-map', + plugins: [new WebpackCLITestPlugin()], }; diff --git a/test/help/__snapshots__/help.test.js.snap.webpack4 b/test/help/__snapshots__/help.test.js.snap.webpack4 index 5794067bd7b..7827dfe8b5d 100644 --- a/test/help/__snapshots__/help.test.js.snap.webpack4 +++ b/test/help/__snapshots__/help.test.js.snap.webpack4 @@ -77,6 +77,7 @@ Options: -o, --output-path Output location of the file generated by webpack e.g. ./dist/. -t, --target Sets the build target e.g. node. -d, --devtool Determine source maps to use. + --no-devtool Do not generate source maps. --mode Defines the mode to pass to webpack. --name Name of the configuration. Used when loading multiple configurations. --stats [value] It instructs webpack on how to treat the stats e.g. verbose. @@ -130,6 +131,7 @@ Options: -o, --output-path Output location of the file generated by webpack e.g. ./dist/. -t, --target Sets the build target e.g. node. -d, --devtool Determine source maps to use. + --no-devtool Do not generate source maps. --mode Defines the mode to pass to webpack. --name Name of the configuration. Used when loading multiple configurations. --stats [value] It instructs webpack on how to treat the stats e.g. verbose. @@ -183,6 +185,7 @@ Options: -o, --output-path Output location of the file generated by webpack e.g. ./dist/. -t, --target Sets the build target e.g. node. -d, --devtool Determine source maps to use. + --no-devtool Do not generate source maps. --mode Defines the mode to pass to webpack. --name Name of the configuration. Used when loading multiple configurations. --stats [value] It instructs webpack on how to treat the stats e.g. verbose. @@ -240,6 +243,7 @@ Options: e.g. ./dist/. -t, --target Sets the build target e.g. node. -d, --devtool Determine source maps to use. + --no-devtool Do not generate source maps. --mode Defines the mode to pass to webpack. --name Name of the configuration. Used when loading multiple configurations. @@ -418,6 +422,7 @@ Options: e.g. ./dist/. -t, --target Sets the build target e.g. node. -d, --devtool Determine source maps to use. + --no-devtool Do not generate source maps. --mode Defines the mode to pass to webpack. --name Name of the configuration. Used when loading multiple configurations. @@ -500,6 +505,7 @@ Options: e.g. ./dist/. -t, --target Sets the build target e.g. node. -d, --devtool Determine source maps to use. + --no-devtool Do not generate source maps. --mode Defines the mode to pass to webpack. --name Name of the configuration. Used when loading multiple configurations. @@ -542,6 +548,7 @@ Options: -o, --output-path Output location of the file generated by webpack e.g. ./dist/. -t, --target Sets the build target e.g. node. -d, --devtool Determine source maps to use. + --no-devtool Do not generate source maps. --mode Defines the mode to pass to webpack. --name Name of the configuration. Used when loading multiple configurations. --stats [value] It instructs webpack on how to treat the stats e.g. verbose. @@ -595,6 +602,7 @@ Options: -o, --output-path Output location of the file generated by webpack e.g. ./dist/. -t, --target Sets the build target e.g. node. -d, --devtool Determine source maps to use. + --no-devtool Do not generate source maps. --mode Defines the mode to pass to webpack. --name Name of the configuration. Used when loading multiple configurations. --stats [value] It instructs webpack on how to treat the stats e.g. verbose.