• Stars
    star
    238
  • Rank 169,306 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 11 years ago
  • Updated almost 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Skeleton project for building javascript libraries using Require.js

Require.js Library Skeleton

Build Status devDependency Status

Getting Started

The project depends on Bower and Gulp.js. Assuming you already have Node.js installed on your system, run the following command:

sudo npm install -g gulp bower

Next, clone the repository and install project dependencies:

# Fetch only the latest commits.
git clone --depth=1 [email protected]:sahat/requirejs-library.git

cd requirejs-library

bower install
npm install

With Bower you get the following libraries:

  • Almond - A replacement AMD loader for RequireJS, providing the minimal AMD API footprint.
  • Require.js - Used as an asynchronous module loader.
  • Jasmine - Popular BDD testing framework.
  • Mocha - Another great testing framework.
  • Chai - BDD/TDD assertion library (used with Mocha).

And with npm you get the following packages:

  • Gulp - Ultra-fast JavaScript task runner.
  • Require.js - Used as an optimization tool that lets you to compile a single, minified JavaScript file.
  • Karma - Awesome JavaScript test runner.

Usage

This library is flexible enough to work as an inline <script> declaration, Require.js module, or in this case as a Node.js module: alt tex

You can run all demos right away out of the box, but if you have changed any of the src files, simply run the following command to re-build the library and start watching for changes:

gulp

Source Maps

Require.js optimizer comes with a built-in support to generate source maps. It is already enabled in gulpfile by default, but feel free to disable source maps. Refer to this article to enable source maps in Google Chrome, if you haven't already done so. alt text

Tests

Go to the test folder and run SpecRunnerJasmine.html and you should see the following page: alt text Only 2 out of 3 specs in the test/spec folder are written for the Jasmine testing framework: slugify.js, random.js. For your project pick either Jasmine or Mocha + Chai, whichever one you prefer the most. Both testing frameworks are excellent.

The other file, capitalize.js is written for the Mocha testing framework, using Chai's should assertions. Run the SpecRunnerMocha.html and you should see the following page: alt text

And lastly, if you prefer to run your tests with Karma, simply run:

npm test

Or if you have installed Karma globally via npm, first run karma start, then karma run. It will perform a single test run using Jasmine testing framework via PhantomJS headless browser. Both testing framework and browser are configurable in karma.conf.js.

I have set autoWatch: false by default. So, if you use something like JetBrains WebStorm 7 for development, then you should keep autoWatch turned off. Here is the step-by-step guide: Running JavaScript tests with Karma in WebStorm 7

Structure

  • demo - examples with Inline, AMD, CommonJS script loading
  • dist - minified JavaScript file + source map
  • src/mylib.js - entry-file that pulls all other modules
  • src/_start.js - adds compatibility for AMD, CommonJS and Browser globals
  • src/_end.js - serves the same purpose of the initial require() call that data-main does
  • test/spec - jasmine and mocha specs
  • test/SpecRunnerJasmine.html - standalone jasmine html spec runner
  • test/SpecRunnerMocha.html - standalone mocha html spec runner
  • karma.conf.js β€” karma test runner configuration
  • test/test-main.js β€” configures karma to use Require.js for the tests

Additional Notes

  • When you are changing library's name from mylib to YOUR_LIBRARY_NAME, update names in the following locations:
  • src/mylib.js: filename
  • gulpfile.js: out, out: "dist/YOUR_LIBRARY_NAME.js"
  • gulpfile.js: include, include: ['almond', 'YOUR_LIBRARY_NAME']
  • src/_start.js: else statement, window.YOUR_LIBRARY_NAME = factory();
  • src/_end.js: return statement, require('YOUR_LIBRARY_NAME');

Contributing

If you have any suggestions, or found a bug please open a GitHub issue and I will get to it as soon as I can.

License

The MIT License (MIT)

Copyright (c) 2014 Sahat Yalkabov

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.

More Repositories

1

hackathon-starter

A boilerplate for Node.js web applications
JavaScript
34,785
star
2

satellizer

Token-based AngularJS Authentication
TypeScript
7,858
star
3

megaboilerplate

Handcrafted starter projects, optimized for simplicity and ease of use.
CSS
3,829
star
4

newedenfaces-react

Character voting app for EVE Online
JavaScript
849
star
5

tvshow-tracker

AngularJS + Node + Gulp + Mongoose + Passport Authentication + TVDB API
JavaScript
593
star
6

instagram-hackhands

Source code for HackHands blog post
CSS
292
star
7

jsrecipes

Source Code for JSRecipes
CSS
255
star
8

ember-sass-express-starter

Starter project for Ember+Express apps
CSS
91
star
9

vplayer

Custom HTML5 Video Player
JavaScript
43
star
10

coffeed

Ordering system for a coffee shop
CSS
24
star
11

react-satellizer

IN PROGRESS
JavaScript
24
star
12

cloudbucket

Capstone II project at the City College of New York
JavaScript
15
star
13

ui-patterns

Ready to use UI patterns for websites
HTML
14
star
14

GameOn

Node.js back-end for iOS application
JavaScript
14
star
15

newedenfaces

eve online facemash clone
CSS
10
star
16

gaia000

Visit
JavaScript
9
star
17

react-starter

JavaScript
9
star
18

csc322

Game recommendation engine + online shop for CCNY Software Engineering course
JavaScript
8
star
19

apparelist

shopping from multiple stores
CSS
7
star
20

HotOrNot

Hot or Not clode in node.js
CSS
4
star
21

pascal.js

Pascal compiler written in JavaScript
JavaScript
3
star
22

yahoo-oauth2-tutorial

Tumblr Yahoo OAuth 2.0 Tutorial Code
JavaScript
3
star
23

skeleton

Node Express MongoDB Bootstrap Passport... all rolled up into juicy goodness
CSS
3
star
24

audiostreamer

initial senior project idea
JavaScript
3
star
25

DropboxChallenge

Dropbox Interview Project
JavaScript
3
star
26

heap-mailchimp

Heap Analytics + MailChimp Integration
JavaScript
2
star
27

markdown

work in progress
JavaScript
2
star
28

hsc

Comprehensive HTTP Status Code Information in Node.js Made Easy!
JavaScript
2
star
29

express-authentication-demo

Basic Express website with built-in username + password authentication
JavaScript
2
star
30

esoterikmusic

Esoterik band website
CSS
1
star
31

megaboilerplate-example-3

express-nunjucks-postcss-unstyled-react-webpack-mocha-sqlite-twitter
JavaScript
1
star
32

backbone-tools

build and scaffolding tool inspired by ember-tools
1
star
33

bbb

Backbone Boilerplate
JavaScript
1
star
34

trip-planner

JavaScript
1
star
35

yahoo-ios-sdk

work in progress
Swift
1
star
36

graphql-starter

1
star
37

apihackday

App for finding team members during hackathons
JavaScript
1
star
38

continuum-best-practices

Skeleton Project using Best Practices
JavaScript
1
star
39

express-satellizer

1
star
40

disrupt2015

TechCrunch Disrupt SF 2015 Hackathon
JavaScript
1
star
41

mastersofcode-web

Web interface for Masters of Code hackathon
JavaScript
1
star