/n8-make

Opinionated Makefile to build ES6 JS, JSX and Pug files

Primary LanguageMakefile

n8-make

Opinionated Makefile to build ES6 JS, JSX and Pug files

n8-make is a wrapper around make with a Makefile designed to compile JavaScript (and related) files for usage with Node.js and the web browser.

By default, these file extensions get compiled into the build directory:

Installation

Install with npm:

$ npm install --save-dev n8-make

Usage

The n8-make command invokes the system's make with its Makefile. Any arguments you pass to n8-make get passed along to make.

The Makefile has a few built-in rules:

build (default)

$ n8-make
# or
$ n8-make build

Compiles all files matching the extensions in the current directory and nested directories.

A few paths are ignored by default, and will not be compiled:

  • build (or whatever $(BUILDDIR) get set to)
  • node_modules
  • public
  • webpack.config.js

clean

$ n8-make clean

Deletes the build directory (or whatever $(BUILDDIR) get set to).

distclean

$ n8-make distclean

Deletes the node_modules directory.

Source

The source files and/or folders can be defined by passing SOURCE env to n8-make.

n8-make build SOURCE=lib

Custom extensions

For every file that gets compiled, a specialized executable is invoked for each file extension. For example, given the .js file extension, n8-make will invoke n8-make-js inputfile.js build/outputfile.js and the output file is generated from there.

You may override the default extensions by passing EXTENSIONS env to n8-make. Say you wanted to use n8-make to compile .coffee files into js:

$ n8-make build EXTENSIONS=coffee

But make sure you have a n8-make-coffee executable in your $PATH at this point!

HINT! n8-make inherits npm's bin directory, so you can utilize devDependencies in your package.json file to include said executable.

Extending the Makefile

If you would still prefer to have your own Makefile, say to add additional rules or tweak existing variables, then you can easily extend the n8-make Makefile using the following syntax:

include $(shell node -e "require('n8-make')")

This assumes that n8-make is a dependency of your project.

License

(The MIT License)

Copyright (c) 2016 Nathan Rajlich <n@n8.io>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.