Skip to content
This repository has been archived by the owner on Oct 30, 2022. It is now read-only.

Commit

Permalink
Split out rollup scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurClemens committed Dec 20, 2016
1 parent e9755f4 commit 617fceb
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 58 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "./src/index";
58 changes: 0 additions & 58 deletions rollup.config.js

This file was deleted.

46 changes: 46 additions & 0 deletions scripts/rollup.base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import fs from "fs";
import babel from "rollup-plugin-babel";
import eslint from "rollup-plugin-eslint";
import resolve from "rollup-plugin-node-resolve";
import commonjs from "rollup-plugin-commonjs";

export const pkg = JSON.parse(fs.readFileSync("./package.json"));
const external = Object.keys(pkg.dependencies || {});

const globals = {};
external.forEach(ext => {
switch (ext) {
case "mithril":
globals["mithril"] = "m";
break;
default:
globals[ext] = ext;
}
});

export const createConfig = ({ includeDepencies }) => ({
entry: "index.js",
external: includeDepencies ? null : external,
globals,
plugins: [

// Resolve libs in node_modules
resolve({
jsnext: true,
main: true,
skip: includeDepencies ? [] : external
}),

// Convert CommonJS modules to ES6, so they can be included in a Rollup bundle
commonjs({
include: "node_modules/**"
}),

eslint({
cache: true
}),

babel()
]
});

16 changes: 16 additions & 0 deletions scripts/rollup.es.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
Build to a module that has ES2015 module syntax but otherwise only syntax features that node supports
https://github.com/rollup/rollup/wiki/jsnext:main
*/
import { pkg, createConfig } from "./rollup.base.js";

const includeDepencies = true; // Use `false` if you are creating a library

const baseConfig = createConfig({ includeDepencies });
const targetConfig = Object.assign({}, baseConfig, {
dest: pkg["jsnext:main"],
format: "es"
});

export default targetConfig;

19 changes: 19 additions & 0 deletions scripts/rollup.umd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
Build to an Universal Module Definition
*/
import { pkg, createConfig } from "./rollup.base.js";
import uglify from "rollup-plugin-uglify";

const includeDepencies = true; // Use `false` if you are creating a library, or if you are including external script in html

const baseConfig = createConfig({ includeDepencies });
const targetConfig = Object.assign({}, baseConfig, {
dest: pkg.main,
format: "umd",
sourceMap: true
});

targetConfig.plugins.push(uglify());

export default targetConfig;

0 comments on commit 617fceb

Please sign in to comment.