Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

build script in package.json using webpack with --config flag as

Tags:

npm

In my package.json I'm trying to use webpack in a script but it keeps failing.

  "scripts": {     "start": "node server.js",     "test": "mocha 'src/**/test*.coffee' --watch --compilers coffee:coffee-script/register",     "build": "webpack --config webpack.dist.config.js"   }, 

the scripts start and test works as expected but when running npm build in terminal I'm getting nothing:

➜  client git:(master) ✗ npm build ➜  client git:(master) ✗  

When running the command manually, things happen:

➜  client git:(master) ✗ webpack --config webpack.dist.config.js Hash: 9274a04acd39605afc25 Version: webpack 1.9.10 Time: 5206ms     Asset     Size  Chunks             Chunk Names bundle.js  5.23 MB       0  [emitted]  main    [0] multi main 28 bytes {0} [built]  [349] ../config.js 181 bytes {0} [built]     + 413 hidden modules ➜  client git:(master) ✗  

Have I miss understod how npm scripts are suppose to work?

like image 620
Cotten Avatar asked Jan 16 '16 17:01

Cotten


People also ask

What is webpack in package json?

Webpack is used to compile JavaScript modules. Once installed, you can interact with webpack either from its CLI or API. If you're still new to webpack, please read through the core concepts and this comparison to learn why you might use it over the other tools that are out in the community.

Where do I put webpack config?

The easiest way to get your webpack. config. js file to work is to place it at the top level of your project's folder structure along with your package.


2 Answers

Use: npm run build

Reason: npm start & npm test are shortcuts for npm run start & npm run test, for any other npm tasks, you have to specify "run"

like image 147
topheman Avatar answered Nov 11 '22 19:11

topheman


Run npm run build.

start and test are built in scripts for npm. build however is a custom script and thus needs to be invoked with npm run build.

You can find out more about npm's scripts here

like image 38
Mario Tacke Avatar answered Nov 11 '22 20:11

Mario Tacke