Skip to content

Commit

Permalink
Modernize the build system a bit.
Browse files Browse the repository at this point in the history
- Use mocha.opts to make it easier to run tests from IDEs.
- Use explicit extensions in imports.
- Use `targets` option to consolidate rollup config.
- Use the `es2015` preset by default, and use `babelrc-rollup` to swap the presets as needed.
  • Loading branch information
eventualbuddha committed Jun 9, 2016
1 parent dae5f8b commit 43c2e17
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"presets": [ "es2015-rollup" ]
"presets": [ "es2015" ]
}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
build
dist
node_modules
53 changes: 28 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,22 @@ This is the starting point for tests in your package. You should import the
code to test from `lib/` as shown in the example. The project is already
configured to use mocha when you run `npm test`.

### dist/rollup-starter-project.umd.js
### dist/rollup-starter-project.js

This is the `main` file of the package and includes all the code needed to run
your package. If your package has dependencies you do not want bundled, be sure
to configure rollup to exclude them by marking them as `external`.
your package. It is in UMD format, meaning it can be used in most JavaScript
runtime environments. If your package has dependencies you do not want bundled,
be sure to configure rollup to exclude them by marking them as `external`. By
default all `dependencies` entries in your `package.json` will be `external`.

### dist/rollup-starter-project.es6.js
### dist/rollup-starter-project.mjs

This is the `jsnext:main` file of the package and includes all the code needed
to run your package. Compared to the `umd` version, this one preserves ES6
imports and exports at the package boundary for tools that support it (such as
rollup). If your package has dependencies you do not want bundled, be sure to
configure rollup to exclude them by marking them as `external`.
to run your package. Compared to the UMD version, this one preserves ES6 imports
and exports at the package boundary for tools that support it (such as rollup).
If your package has dependencies you do not want bundled, be sure to configure
rollup to exclude them by marking them as `external`. By default all
`dependencies` entries in your `package.json` will be `external`.

### .eslintrc

Expand All @@ -63,6 +66,12 @@ Enables eslint to understand all JavaScript syntax that
code. This can be removed if you plan not to use babel to transform ES2015 code
to ES5 or if you plan not to use eslint.

### babel-preset-es2015

Used when babel is used without rollup, and referenced by the `.babelrc` file.
This can be removed if you plan not to use babel to transform ES2015 code to ES5
or you plan to specify all the babel plugins manually.

### babel-preset-es2015-rollup

The base preset of babel plugins required to support all ES2015 syntax is the
Expand All @@ -71,6 +80,17 @@ support for ES2015 modules since rollup handles them instead of babel. This can
be removed if you plan not to use babel to transform ES2015 code to ES5 or you
plan to specify all the babel plugins manually.

### babel-register

Provides on-demand transpilation via babel so no precompilation is required.
This is used in the tests to allow running them without compiling first, and is
referenced in `test/mocha.opts`.

### babelrc-rollup

Handles transforming the babel config from `.babelrc` to one suitable for use
with `rollup-plugin-babel`, where you don't want to use any module plugins.

### eslint

[eslint](http://eslint.org) checks your code for common errors and ensures it
Expand All @@ -95,23 +115,6 @@ to remove this dependency.
This plugin enables support for [babel](http://babeljs.io), which transforms
ES2015 code to ES5. You can remove this if you plan not to use ES2015 code.

### rollup-plugin-multi-entry

Used in `rollup.config.test.js` to enable using all the testing files as the
entry point for the test build. You can remove this if you only have a single
test file, or if you want to test your built file in `dist/` instead of
referencing your source files directly. Doing so has the advantage of testing
the exact bytes that you plan to distribute, but the disadvantage of being
unable to unit test private module functionality (i.e. you can only test things
exported by your package). A hybrid approach might be the best of both worlds.

### source-map-support

Used in `rollup.config.test.js` to provide error messages with stack traces
referencing the original source files. You can remove this if you do not care
about stack trace lines matching source files, or if you use some other
mechanism to achieve this.

## Contributing

If you think a project built with rollup should be set up differently, open an
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* this package does), let rollup bundle them into your dist file.
*/

import { add } from './utils';
import { add } from './utils.js';

/**
* Multiply two numbers together, returning the product.
Expand Down
34 changes: 18 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
"name": "rollup-starter-project",
"version": "1.0.0",
"description": "Sample project for packages built with rollup.",
"main": "dist/rollup-starter-project.umd.js",
"jsnext:main": "dist/rollup-starter-project.es6.js",
"main": "dist/rollup-starter-project.js",
"jsnext:main": "dist/rollup-starter-project.mjs",
"scripts": {
"prebuild": "eslint lib test",
"build": "rollup -c rollup.config.umd.js && rollup -c rollup.config.es6.js",
"pretest": "rollup -c rollup.config.test.js",
"test": "mocha build/test-bundle.js",
"prepublish": "npm run build && npm test"
"build": "rollup -c",
"pretest": "npm run build",
"test": "mocha",
"prepublish": "npm test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/eventualbuddha/rollup-starter-project.git"
"url": "git+https://github.com/rollup/rollup-starter-project.git"
},
"keywords": [
"es6",
Expand All @@ -25,21 +25,23 @@
"author": "Brian Donovan",
"license": "MIT",
"bugs": {
"url": "https://github.com/eventualbuddha/rollup-starter-project/issues"
"url": "https://github.com/rollup/rollup-starter-project/issues"
},
"files": [
"lib",
"dist"
],
"homepage": "https://github.com/eventualbuddha/rollup-starter-project#readme",
"homepage": "https://github.com/rollup/rollup-starter-project#readme",
"dependencies": {},
"devDependencies": {
"babel-eslint": "^6.0.0",
"babel-eslint": "^6.0.4",
"babel-preset-es2015": "^6.9.0",
"babel-preset-es2015-rollup": "^1.1.1",
"eslint": "^2.5.3",
"mocha": "^2.4.5",
"rollup": "^0.26.2",
"rollup-plugin-babel": "^2.4.0",
"rollup-plugin-multi-entry": "^1.2.0",
"source-map-support": "^0.4.0"
"babel-register": "^6.9.0",
"babelrc-rollup": "^1.1.0",
"eslint": "^2.11.1",
"mocha": "^2.5.3",
"rollup": "^0.29.0",
"rollup-plugin-babel": "^2.5.1"
}
}
6 changes: 0 additions & 6 deletions rollup.config.es6.js

This file was deleted.

21 changes: 19 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
import babel from 'rollup-plugin-babel';
import babelrc from 'babelrc-rollup';

let pkg = require('./package.json');
let external = Object.keys(pkg.dependencies);

export default {
entry: 'lib/index.js',
sourceMap: true,
plugins: [babel()]
plugins: [babel(babelrc())],
external: external,
targets: [
{
dest: pkg['main'],
format: 'umd',
moduleName: 'rollupStarterProject',
sourceMap: true
},
{
dest: pkg['jsnext:main'],
format: 'es6',
sourceMap: true
}
]
};
11 changes: 0 additions & 11 deletions rollup.config.test.js

This file was deleted.

7 changes: 0 additions & 7 deletions rollup.config.umd.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/index_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { multiply } from '../lib/index';
import { multiply } from '../';
import { strictEqual } from 'assert';

describe('multiply', () => {
Expand Down
1 change: 1 addition & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--recursive --compilers js:babel-register

0 comments on commit 43c2e17

Please sign in to comment.