Skip to content

Npm scripts

Allyson Souza edited this page Dec 3, 2018 · 3 revisions

We decided to use npm as our task runner. Why? Because it's easy to set up, fast and realiable. We're using some really simples tasks like compile Sass and uglify JavaScript, and we already uses npm to install some modules like Bootstrap, so, why not use just it?

But you're not obligated to use npm scripts, feel free to use nothing or a task runner of your preference.

Installing

The modules that are used are defined into package.json, to install the packages, open your terminal, go to the theme directory and type: npm install. That command will create a directory called node_modules and will store all the modules here.

You must install globally the npm package gnomon, used to measure the time spent on each task. Type npm install -g gnomon to install it. Once the modules are installed, you can use the npm scripts define in package.json.

Commands

See the list of available commands.

npm run sass

Use npm run sass to compile all the .scss in /src/scss to .css into /assets/css

npm run uglify

Use npm run uglify to combine and minify JavaScript from /src/js to /assets/js

npm run lint

Use npm run lint to run eslint to check all .js in /src/js. ESlint configs are defined in .eslintrc.json. See https://eslint.org/ to know more.

npm run watch

Use npm run watch to let the scripts constantly looking for changes in js/css and running Sass compiling and JavaScript lint and uglify.