I have installed webpack using
npm install -g webpack
and
npm install webpack
I also installed webpack-dev-server
npm install -g webpack-dev-server
After completion of installation, I ran the command webpack but, it shows below error
webpack: command not found
I am not getting what is the error.
Your webpack exists in ./node_modules/.bin/ folder . So you should execute this command :
./node_modules/.bin/webpack
Check out the answer in this thread .
As a good practice is recommended to install webpack
and webpack-dev-server
locally, more info here.
yarn add webpack webpack-dev-server --dev
# or
npm install webpack webpack-dev-server --save-dev
Then you can add these lines to your scripts section in your package.json file.
"scripts": {
"build": "webpack --progress --colors",
"start": "webpack-dev-server --progress --colors"
}
and finally
npm start
npm run build
Note: You need to have a
webpack.config.js
in the root folder to make it run correctly.
I needed to manually install:
npm install --save-dev webpack-cli
I guess its needed so that Angular CLI actually understands the commands related to Webpack.
If you want to use global installation, you can find webpack script in [node_installed_path]/lib/node_modules/webpack/bin/
, you can use with absolute path, adding to PATH
environment variable, or symbolic link, etc.
If you want to use local installation, find it in ./node_modules/.bin/
.
I recommand using local installation (for same reason about babel).
来源:https://stackoverflow.com/questions/44845143/webpack-command-not-found