├── .babelrc
├── .eslintignore
├── .eslintrc
├── .gitignore
├── .npmignore
├── .travis.yml
├── CHANGELOG.md
├── CODE_OF_CONDUCT.md
├── LICENSE.md
├── README.md
├── examples
└── simple
│ ├── components
│ └── App.js
│ ├── index.html
│ ├── index.js
│ ├── package.json
│ ├── server.js
│ └── webpack.config.js
├── package.json
├── src
└── index.js
├── test
├── index.spec.js
├── mocha.opts
└── utils
│ └── document.js
└── webpack.config.js
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "stage": 0,
3 | "loose": "all"
4 | }
5 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | lib
2 | **/node_modules
3 | **/webpack.config.js
4 | examples/**/server.js
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "eslint-config-airbnb",
3 | "env": {
4 | "browser": true,
5 | "mocha": true,
6 | "node": true
7 | },
8 | "rules": {
9 | "react/jsx-uses-react": 2,
10 | "react/jsx-uses-vars": 2,
11 | "react/react-in-jsx-scope": 2
12 | },
13 | "plugins": [
14 | "react"
15 | ]
16 | }
17 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | *.log
3 | .DS_Store
4 | dist
5 | lib
6 | coverage
7 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | *.log
3 | src
4 | test
5 | examples
6 | coverage
7 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - "iojs"
4 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change log
2 |
3 | All notable changes to this project will be documented in this file.
4 | This project adheres to [Semantic Versioning](http://semver.org/).
5 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Code of Conduct
2 |
3 | As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4 |
5 | We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6 |
7 | Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8 |
9 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10 |
11 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12 |
13 | This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
14 |
15 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 library-boilerplate-author
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | library-boilerplate
2 | =========================
3 |
4 | An opinionated setup I plan to use for my libraries.
5 |
6 | It has CommonJS and UMD builds via Babel and Webpack, ESLint, and Mocha.
7 | It also has React-friendly examples folder with library code mapped to the sources.
8 |
9 | If you use this, make sure to grep for “library-boilerplate” and replace every occurrence.
10 | See `package.json` in the root and the example folder for the list of the available commands.
11 |
12 | Note that this is an *opinionated* boilerplate. You might want to:
13 |
14 | * Set `stage` to `2` in `.babelrc` so you don’t depend on language features that might be gone tomorrow;
15 | * Remove `loose: ["all"]` from `.babelrc` so the behavior is spec-compliant.
16 |
17 | You have been warned.
18 |
--------------------------------------------------------------------------------
/examples/simple/components/App.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { add } from 'library-boilerplate';
3 |
4 | export default class App extends Component {
5 | render() {
6 | return (
7 |
8 | 2 + 2 = {add(2, 2)}
9 |
10 | );
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/examples/simple/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | library-boilerplate-example-title
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/examples/simple/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import App from './components/App';
3 |
4 | React.render(
5 | ,
6 | document.getElementById('root')
7 | );
8 |
--------------------------------------------------------------------------------
/examples/simple/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "library-boilerplate-example",
3 | "version": "1.0.0",
4 | "description": "library-boilerplate-example-description",
5 | "main": "server.js",
6 | "scripts": {
7 | "start": "node server.js"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/library-boilerplate-author/library-boilerplate.git"
12 | },
13 | "keywords": [
14 | "library-boilerplate-keywords"
15 | ],
16 | "license": "MIT",
17 | "bugs": {
18 | "url": "https://github.com/library-boilerplate-author/library-boilerplate/issues"
19 | },
20 | "homepage": "https://github.com/library-boilerplate-author/library-boilerplate",
21 | "dependencies": {
22 | "react": "^0.13.3"
23 | },
24 | "devDependencies": {
25 | "babel-core": "^5.6.18",
26 | "babel-loader": "^5.1.4",
27 | "node-libs-browser": "^0.5.2",
28 | "react-hot-loader": "^1.2.7",
29 | "webpack": "^1.9.11",
30 | "webpack-dev-server": "^1.9.0"
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/examples/simple/server.js:
--------------------------------------------------------------------------------
1 | var webpack = require('webpack');
2 | var WebpackDevServer = require('webpack-dev-server');
3 | var config = require('./webpack.config');
4 |
5 | new WebpackDevServer(webpack(config), {
6 | publicPath: config.output.publicPath,
7 | hot: true,
8 | historyApiFallback: true,
9 | stats: {
10 | colors: true
11 | }
12 | }).listen(3000, 'localhost', function (err) {
13 | if (err) {
14 | console.log(err);
15 | }
16 |
17 | console.log('Listening at localhost:3000');
18 | });
19 |
--------------------------------------------------------------------------------
/examples/simple/webpack.config.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | var webpack = require('webpack');
3 |
4 | module.exports = {
5 | devtool: 'eval',
6 | entry: [
7 | 'webpack-dev-server/client?http://localhost:3000',
8 | 'webpack/hot/only-dev-server',
9 | './index'
10 | ],
11 | output: {
12 | path: path.join(__dirname, 'dist'),
13 | filename: 'bundle.js',
14 | publicPath: '/static/'
15 | },
16 | plugins: [
17 | new webpack.HotModuleReplacementPlugin(),
18 | new webpack.NoErrorsPlugin()
19 | ],
20 | resolve: {
21 | alias: {
22 | 'library-boilerplate': path.join(__dirname, '..', '..', 'src')
23 | },
24 | extensions: ['', '.js']
25 | },
26 | module: {
27 | loaders: [{
28 | test: /\.js$/,
29 | loaders: ['react-hot', 'babel'],
30 | exclude: /node_modules/,
31 | include: __dirname
32 | }, {
33 | test: /\.js$/,
34 | loaders: ['babel'],
35 | include: path.join(__dirname, '..', '..', 'src')
36 | }]
37 | }
38 | };
39 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "library-boilerplate",
3 | "version": "1.0.0",
4 | "description": "library-boilerplate-description",
5 | "main": "lib/index.js",
6 | "scripts": {
7 | "clean": "rimraf lib dist",
8 | "build": "babel src --out-dir lib",
9 | "build:umd": "webpack src/index.js dist/library-boilerplate.js && NODE_ENV=production webpack src/index.js dist/library-boilerplate.min.js",
10 | "lint": "eslint src test examples",
11 | "test": "NODE_ENV=test mocha",
12 | "test:watch": "NODE_ENV=test mocha --watch",
13 | "test:cov": "babel-node ./node_modules/.bin/isparta cover ./node_modules/.bin/_mocha",
14 | "prepublish": "npm run lint && npm run test && npm run clean && npm run build && npm run build:umd"
15 | },
16 | "repository": {
17 | "type": "git",
18 | "url": "https://github.com/library-boilerplate-author/library-boilerplate.git"
19 | },
20 | "keywords": [
21 | "library-boilerplate-keywords"
22 | ],
23 | "author": "library-boilerplate-author",
24 | "license": "MIT",
25 | "bugs": {
26 | "url": "https://github.com/library-boilerplate-author/library-boilerplate/issues"
27 | },
28 | "homepage": "https://github.com/library-boilerplate-author/library-boilerplate",
29 | "devDependencies": {
30 | "babel": "^5.5.8",
31 | "babel-core": "^5.6.18",
32 | "babel-eslint": "^3.1.15",
33 | "babel-loader": "^5.1.4",
34 | "eslint": "^0.23",
35 | "eslint-config-airbnb": "0.0.6",
36 | "eslint-plugin-react": "^2.3.0",
37 | "expect": "^1.6.0",
38 | "isparta": "^3.0.3",
39 | "mocha": "^2.2.5",
40 | "rimraf": "^2.3.4",
41 | "webpack": "^1.9.6",
42 | "webpack-dev-server": "^1.8.2"
43 | },
44 | "dependencies": {
45 | "invariant": "^2.0.0"
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | export function add(x, y) {
2 | return x + y;
3 | }
4 |
--------------------------------------------------------------------------------
/test/index.spec.js:
--------------------------------------------------------------------------------
1 | import expect from 'expect';
2 | import { add } from '../src';
3 |
4 | describe('add', () => {
5 | it('should add 2 and 2', () => {
6 | expect(add(2, 2)).toBe(4);
7 | });
8 | });
9 |
--------------------------------------------------------------------------------
/test/mocha.opts:
--------------------------------------------------------------------------------
1 | --compilers js:babel/register
2 | --recursive
3 |
--------------------------------------------------------------------------------
/test/utils/document.js:
--------------------------------------------------------------------------------
1 | if (typeof document === 'undefined') {
2 | global.document = {};
3 | }
4 |
--------------------------------------------------------------------------------
/webpack.config.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var webpack = require('webpack');
4 |
5 | var plugins = [
6 | new webpack.optimize.OccurenceOrderPlugin(),
7 | new webpack.DefinePlugin({
8 | 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
9 | })
10 | ];
11 |
12 | if (process.env.NODE_ENV === 'production') {
13 | plugins.push(
14 | new webpack.optimize.UglifyJsPlugin({
15 | compressor: {
16 | screw_ie8: true,
17 | warnings: false
18 | }
19 | })
20 | );
21 | }
22 |
23 | module.exports = {
24 | module: {
25 | loaders: [{
26 | test: /\.js$/,
27 | loaders: ['babel-loader'],
28 | exclude: /node_modules/
29 | }]
30 | },
31 | output: {
32 | library: 'library-boilerplate',
33 | libraryTarget: 'umd'
34 | },
35 | plugins: plugins,
36 | resolve: {
37 | extensions: ['', '.js']
38 | }
39 | };
40 |
--------------------------------------------------------------------------------