Skip to content

Commit

Permalink
feat: enhanced rollup configuration (Hacker0x01#1883)
Browse files Browse the repository at this point in the history
* feat: enhanced rollup configuration

* feat: cleaned up
  • Loading branch information
mxschmitt authored and martijnrusschen committed Aug 29, 2019
1 parent ddb6f50 commit f505c11
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 116 deletions.
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"license": "MIT",
"homepage": "https://github.com/Hacker0x01/react-datepicker",
"main": "lib/index.js",
"module": "es",
"browser": "dist/react-datepicker.min.js",
"module": "es/index.js",
"unpkg": "dist/react-datepicker.min.js",
"style": "dist/react-datepicker.min.css",
"files": [
Expand Down Expand Up @@ -83,7 +84,12 @@
"rollup": "^1.20.2",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-commonjs": "^10.0.2",
"rollup-plugin-filesize": "^6.2.0",
"rollup-plugin-local-resolve": "^1.0.7",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-peer-deps-external": "^2.2.0",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-terser": "^5.1.1",
"rollup-plugin-uglify": "^6.0.2",
"sass-lint": "^1.13.1",
"sass-loader": "^7.3.1",
Expand Down Expand Up @@ -124,10 +130,7 @@
"css:modules:prod": "node-sass --output-style compressed src/stylesheets/datepicker-cssmodules.scss > dist/react-datepicker-cssmodules.min.css",
"css:dev": "node-sass --output-style expanded src/stylesheets/datepicker.scss > dist/react-datepicker.css",
"css:modules:dev": "node-sass --output-style expanded src/stylesheets/datepicker-cssmodules.scss > dist/react-datepicker-cssmodules.css",
"build:es": "cross-env BABEL_ENV=es rollup -c -i src/index.jsx -o es/index.js",
"build:cjs": "cross-env BABEL_ENV=cjs rollup -c -i src/index.jsx -o lib/index.js",
"build:umd:dev": "cross-env BABEL_ENV=es rollup -c rollup.umd.config.js -i src/index.jsx -o dist/react-datepicker.js",
"build:umd:prod": "cross-env BABEL_ENV=es rollup -c rollup.umd.config.js -i src/index.jsx -o dist/react-datepicker.min.js"
"build:js": "rollup -c"
},
"lint-staged": {
"*.{js,jsx,json,css,scss,md}": [
Expand Down
67 changes: 49 additions & 18 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import fs from "fs";
import path from "path";

import nodeResolve from "rollup-plugin-node-resolve";
import babel from "rollup-plugin-babel";
import peerDepsExternal from "rollup-plugin-peer-deps-external";
import resolve from "rollup-plugin-node-resolve";
import commonjs from "rollup-plugin-commonjs";
import { list as babelHelpersList } from "@babel/helpers";
import filesize from "rollup-plugin-filesize";
import localResolve from "rollup-plugin-local-resolve";
import { terser } from "rollup-plugin-terser";

import replace from "rollup-plugin-replace";
import pkg from "./package.json";

// it's important to mark all subpackages of data-fns as externals
Expand All @@ -13,27 +18,53 @@ const dateFnsDirs = fs
.readdirSync(path.join(".", "node_modules", "date-fns"))
.map(d => `date-fns/${d}`);

const globals = {
react: "React",
"prop-types": "PropTypes",
"react-onclickoutside": "onClickOutside",
"react-popper": "ReactPopper",
classnames: "classNames"
};

const config = {
output: {
format: process.env.BABEL_ENV
},
input: "src/index.jsx",
output: [
{
file: pkg.browser,
format: "umd",
name: "DatePicker",
globals
},
{
file: "dist/react-datepicker.js",
format: "umd",
name: "DatePicker",
globals
},
{
file: pkg.main,
format: "cjs",
name: "DatePicker"
},
{
file: pkg.module,
format: "es"
}
],
plugins: [
nodeResolve({
resolve({
mainFields: ["module"],
extensions: [".js", ".jsx"]
}),
babel({
exclude: "node_modules/**",
plugins: [
"@babel/plugin-external-helpers",
"@babel/plugin-proposal-class-properties"
],
runtimeHelpers: true,
externalHelpersWhitelist: babelHelpersList.filter(
helperName => helperName !== "asyncGenerator"
)
}),
commonjs()
peerDepsExternal(),
babel(),
localResolve(),
commonjs(),
filesize(),
terser(),
replace({
"process.env.NODE_ENV": JSON.stringify("production")
})
],
external: Object.keys(pkg.dependencies)
.concat(Object.keys(pkg.peerDependencies))
Expand Down
33 changes: 0 additions & 33 deletions rollup.umd.config.js

This file was deleted.

55 changes: 0 additions & 55 deletions webpack.config.js

This file was deleted.

Loading

0 comments on commit f505c11

Please sign in to comment.