Reputation: 10351
Especially during the transition from webpack v1 to v2, it would be important to programmatically determine what webpack version is installed, but I cannot seem to find the appropriate API.
Upvotes: 137
Views: 277851
Reputation: 634
npm webpack --version
works for me and it throws something like:
PS C:\Users\alfon\OneDrive\Escritorio\sandbox\fimusicv4\with-redux-app> npm webpack --version
npm WARN config global --global
, --local
are deprecated. Use --location=global
instead.
8.5.5
Upvotes: -2
Reputation: 4951
Just another way not mentioned yet:
If you installed it locally to a project then open up the node_modules folder and check your webpack module.
< /node_modules/webpack/package.json
Open the package.json file and look under version
Upvotes: 29
Reputation: 3000
In CLI
$ webpack --version
webpack-cli 4.1.0
webpack 5.3.2
In Code (node runtime)
process.env.npm_package_devDependencies_webpack // ^5.3.2
or
process.env.npm_package_dependencies_webpack // ^5.3.2
In Plugin
compiler.webpack.version // 5.3.2
Upvotes: 5
Reputation: 1447
Put webpack -v
into your package.json:
{
"name": "js",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack -v",
"dev": "webpack --watch"
}
}
Then enter in the console:
npm run build
Expected output should look like:
> npm run build
> [email protected] build /home/user/repositories/myproject/js
> webpack -v
4.42.0
Upvotes: 4
Reputation: 1003
If using Angular CLI v7+, the webpack version is printed in the output of ng version
:
-> ng version
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 7.0.6
Node: 11.0.0
OS: darwin x64
Angular: 7.1.0
... animations, cdk, common, compiler, compiler-cli, core, forms
... http, language-service, material, platform-browser
... platform-browser-dynamic, router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.10.6
@angular-devkit/build-angular 0.10.6
@angular-devkit/build-optimizer 0.10.6
@angular-devkit/build-webpack 0.10.6
@angular-devkit/core 7.0.6
@angular-devkit/schematics 7.0.6
@angular/cli 7.0.6
@ngtools/webpack 7.0.6
@schematics/angular 7.0.6
@schematics/update 0.10.6
rxjs 6.3.3
typescript 3.1.6
webpack 4.19.1
Upvotes: 9
Reputation: 26751
Using webpack CLI: (--version, -v Show version number [boolean])
webpack --version
or:
webpack -v
Using npm list command:
npm list webpack
Results in name@version-range
:
<projectName>@<projectVersion> /path/to/project
└── webpack@<version-range>
Using yarn list command:
yarn list webpack
Webpack 2 introduced Configuration Types.
Instead of exporting a configuration object, you may return a function which accepts an environment as argument. When running webpack, you may specify build environment keys via
--env
, such as--env.production
or--env.platform=web
.
We will use a build environment key called --env.version
.
webpack --env.version $(webpack --version)
or:
webpack --env.version $(webpack -v)
For this to work we will need to do two things:
Change our webpack.config.js
file and use DefinePlugin.
The DefinePlugin allows you to create global constants which can be configured at compile time.
-module.exports = {
+module.exports = function(env) {
+ return {
plugins: [
new webpack.DefinePlugin({
+ WEBPACK_VERSION: JSON.stringify(env.version) //<version-range>
})
]
+ };
};
Now we can access the global constant like so:
console.log(WEBPACK_VERSION);
Using npm view command will return the latest version available on the registry:
npm view [<@scope>/]<name>[@<version>] [<field>[.<subfield>]...]
For webpack use:
npm view webpack version
Upvotes: 208
Reputation: 4593
For those who are using yarn
yarn list webpack
will do the trick
$ yarn list webpack
yarn list v0.27.5
└─ [email protected]
Done in 1.24s.
Upvotes: 25