Git Product home page Git Product logo

lein-npm's Introduction

lein-npm

Leiningen plugin for enabling Node based ClojureScript projects.

Installation

To enable lein-npm for your project, put the following in the :plugins vector of your project.clj file:

[lein-npm "0.5.0"]

Managing NPM dependencies

You can specify a project's NPM dependencies by adding a :node-dependencies key in your project.clj:

:node-dependencies [[underscore "1.4.3"]
                    [nyancat "0.0.3"]
                    [mongodb "1.2.7"]]

These dependencies, and any :node-dependencies of packages pulled in through the regular :dependencies, will be installed through NPM when you run either lein npm install or lein deps.

Invoking NPM

You can execute NPM commands that require the presence of a package.json file using the lein npm command. This command creates a temporary package.json based on your project.clj before invoking the NPM command you specify. The keys name, description, version and dependencies are automatically added to package.json. Other keys can be specified by adding a :nodejs key in your project.clj:

  :nodejs {:scripts {:test "testem"}}
$ lein npm install        # installs project dependencies
$ lein npm ls             # lists installed dependencies
$ lein npm search nyancat # searches for packages containing "nyancat"

Bower dependencies

lein-bower is a related Leiningen plugin that performs the same service for Bower dependencies. lein-bower itself depends on lein-npm.

Running ClojureScript apps

The plugin installs a lein run hook which enables you to specify a JavaScript file instead of a Clojure namespace for the :main key in your project.clj, like this:

:main "js/main.js"

If :main is a string that refers to a file that exists and ends with .js, it will launch this file using npm start, after first running npm install if necessary. Any command line arguments following lein run will be passed through to the Node process. Note that a scripts.start record will be automatically added to the generated package.json file, simply containing node <value of :main>, but you can override this using the :nodejs key as described above. The :main key will still have to exist and point to a file ending in .js, though, or lein run will stay with its default behaviour.

Changing the directory used

npm does not allow you to put stuff anywhere besides node_modules, even if that name is against your religion, however, you can change the root used by lein-npm to be something other than your project root like this:

:npm-root "resources/public/js"

Or you can use a keyword to look the path up in your project map:

:npm-root :target-path

License

Copyright 2012 Bodil Stokke

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

lein-npm's People

Contributors

myguidingstar avatar bodil avatar ryanmcg avatar ninjudd avatar ilazarte avatar verma avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.