Skip to content

Commit

Permalink
build(rollup): update build to reduce size and target cjs
Browse files Browse the repository at this point in the history
Build has been updated to better target cjs vs esm and provide a size savings.

BREAKING CHANGE: Users relying on the non esm fallback being /lib will need to update their build or
be prepared to receive the cjs build.
  • Loading branch information
bhough committed May 2, 2020
1 parent 6c74e60 commit 7886d94
Show file tree
Hide file tree
Showing 6 changed files with 1,023 additions and 831 deletions.
6 changes: 5 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ module.exports = {
["@babel/env", { loose: true, exclude: [/transform-typeof-symbol/] }],
"@babel/flow"
],
plugins: [cjs && "add-module-exports", "annotate-pure-calls", "preval"].filter(Boolean)
plugins: [
cjs && "add-module-exports",
"annotate-pure-calls",
"preval"
].filter(Boolean)
};
162 changes: 19 additions & 143 deletions docs/assets/polished.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = global || self, factory(global.polished = {}));
}(this, (function (exports) { 'use strict';

function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];

for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@babel/runtime/helpers/esm/extends'), require('@babel/runtime/helpers/esm/assertThisInitialized'), require('@babel/runtime/helpers/esm/inheritsLoose'), require('@babel/runtime/helpers/esm/wrapNativeSuper'), require('@babel/runtime/helpers/esm/taggedTemplateLiteralLoose')) :
typeof define === 'function' && define.amd ? define(['exports', '@babel/runtime/helpers/esm/extends', '@babel/runtime/helpers/esm/assertThisInitialized', '@babel/runtime/helpers/esm/inheritsLoose', '@babel/runtime/helpers/esm/wrapNativeSuper', '@babel/runtime/helpers/esm/taggedTemplateLiteralLoose'], factory) :
(global = global || self, factory(global.polished = {}, global.extends, global.assertThisInitialized, global.inheritsLoose, global.wrapNativeSuper, global.taggedTemplateLiteralLoose));
}(this, (function (exports, _extends, _assertThisInitialized, _inheritsLoose, _wrapNativeSuper, _taggedTemplateLiteralLoose) { 'use strict';

return target;
};

return _extends.apply(this, arguments);
}
_extends = _extends && Object.prototype.hasOwnProperty.call(_extends, 'default') ? _extends['default'] : _extends;
_assertThisInitialized = _assertThisInitialized && Object.prototype.hasOwnProperty.call(_assertThisInitialized, 'default') ? _assertThisInitialized['default'] : _assertThisInitialized;
_inheritsLoose = _inheritsLoose && Object.prototype.hasOwnProperty.call(_inheritsLoose, 'default') ? _inheritsLoose['default'] : _inheritsLoose;
_wrapNativeSuper = _wrapNativeSuper && Object.prototype.hasOwnProperty.call(_wrapNativeSuper, 'default') ? _wrapNativeSuper['default'] : _wrapNativeSuper;
_taggedTemplateLiteralLoose = _taggedTemplateLiteralLoose && Object.prototype.hasOwnProperty.call(_taggedTemplateLiteralLoose, 'default') ? _taggedTemplateLiteralLoose['default'] : _taggedTemplateLiteralLoose;

function last() {
var _ref;
Expand Down Expand Up @@ -240,104 +228,6 @@
}
};

function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}

return self;
}

function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}

function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}

function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};

return _setPrototypeOf(o, p);
}

function _isNativeFunction(fn) {
return Function.toString.call(fn).indexOf("[native code]") !== -1;
}

function isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;

try {
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
return true;
} catch (e) {
return false;
}
}

function _construct(Parent, args, Class) {
if (isNativeReflectConstruct()) {
_construct = Reflect.construct;
} else {
_construct = function _construct(Parent, args, Class) {
var a = [null];
a.push.apply(a, args);
var Constructor = Function.bind.apply(Parent, a);
var instance = new Constructor();
if (Class) _setPrototypeOf(instance, Class.prototype);
return instance;
};
}

return _construct.apply(null, arguments);
}

function _wrapNativeSuper(Class) {
var _cache = typeof Map === "function" ? new Map() : undefined;

_wrapNativeSuper = function _wrapNativeSuper(Class) {
if (Class === null || !_isNativeFunction(Class)) return Class;

if (typeof Class !== "function") {
throw new TypeError("Super expression must either be null or a function");
}

if (typeof _cache !== "undefined") {
if (_cache.has(Class)) return _cache.get(Class);

_cache.set(Class, Wrapper);
}

function Wrapper() {
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
}

Wrapper.prototype = Object.create(Class.prototype, {
constructor: {
value: Wrapper,
enumerable: false,
writable: true,
configurable: true
}
});
return _setPrototypeOf(Wrapper, Class);
};

return _wrapNativeSuper(Class);
}

// based on https://github.com/styled-components/styled-components/blob/fcf6f3804c57a14dd7984dfab7bc06ee2edca044/src/utils/error.js

/**
Expand Down Expand Up @@ -1163,6 +1053,12 @@
};
}

function _createForOfIteratorHelperLoose(o) { var i = 0; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (o = _unsupportedIterableToArray(o))) return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } i = o[Symbol.iterator](); return i.next.bind(i); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

/**
* Returns a set of media queries that resizes a property (or set of properties) between a provided fromSize and toSize. Accepts optional minScreen (defaults to '320px') and maxScreen (defaults to '1200px') to constrain the interpolation.
*
Expand Down Expand Up @@ -1222,21 +1118,10 @@
var mediaQueries = {};
var fallbacks = {};

for (var _iterator = cssProp, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
for (var _iterator = _createForOfIteratorHelperLoose(cssProp), _step; !(_step = _iterator()).done;) {
var _extends2, _extends3;

var _ref;

if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}

var obj = _ref;
var obj = _step.value;

if (!obj.prop || !obj.fromSize || !obj.toSize) {
throw new PolishedError(50);
Expand All @@ -1249,13 +1134,13 @@

return _extends({}, fallbacks, {}, mediaQueries);
} else {
var _ref2, _ref3, _ref4;
var _ref, _ref2, _ref3;

if (!cssProp.prop || !cssProp.fromSize || !cssProp.toSize) {
throw new PolishedError(51);
}

return _ref4 = {}, _ref4[cssProp.prop] = cssProp.fromSize, _ref4["@media (min-width: " + minScreen + ")"] = (_ref2 = {}, _ref2[cssProp.prop] = between(cssProp.fromSize, cssProp.toSize, minScreen, maxScreen), _ref2), _ref4["@media (min-width: " + maxScreen + ")"] = (_ref3 = {}, _ref3[cssProp.prop] = cssProp.toSize, _ref3), _ref4;
return _ref3 = {}, _ref3[cssProp.prop] = cssProp.fromSize, _ref3["@media (min-width: " + minScreen + ")"] = (_ref = {}, _ref[cssProp.prop] = between(cssProp.fromSize, cssProp.toSize, minScreen, maxScreen), _ref), _ref3["@media (min-width: " + maxScreen + ")"] = (_ref2 = {}, _ref2[cssProp.prop] = cssProp.toSize, _ref2), _ref3;
}
}

Expand Down Expand Up @@ -1497,15 +1382,6 @@
return "\n @media only screen and (-webkit-min-device-pixel-ratio: " + ratio + "),\n only screen and (min--moz-device-pixel-ratio: " + ratio + "),\n only screen and (-o-min-device-pixel-ratio: " + ratio + "/1),\n only screen and (min-resolution: " + Math.round(ratio * 96) + "dpi),\n only screen and (min-resolution: " + ratio + "dppx)\n ";
}

function _taggedTemplateLiteralLoose(strings, raw) {
if (!raw) {
raw = strings.slice(0);
}

strings.raw = raw;
return strings;
}

function constructGradientValue(literals) {
var template = '';

Expand Down
44 changes: 24 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
"color",
"colour"
],
"main": "lib/index.js",
"module": "dist/polished.es.js",
"main": "dist/polished.cjs.js",
"jsnext:main": "dist/polished.esm.js",
"module": "dist/polished.esm.js",
"types": "lib/index.d.ts",
"sideEffects": false,
"scripts": {
Expand Down Expand Up @@ -69,43 +70,46 @@
"build:lib": "src/**/*.js"
},
"dependencies": {
"@babel/runtime": "^7.8.7"
"@babel/runtime": "^7.9.2",
"@rollup/plugin-commonjs": "^11.1.0"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.8.7",
"@babel/plugin-transform-runtime": "^7.6.2",
"@babel/core": "^7.9.0",
"@babel/plugin-transform-runtime": "^7.9.0",
"@babel/polyfill": "^7.8.7",
"@babel/preset-env": "^7.8.7",
"@babel/preset-flow": "^7.0.0",
"@rollup/plugin-node-resolve": "^7.1.1",
"@rollup/plugin-replace": "^2.3.1",
"@babel/preset-env": "^7.9.5",
"@babel/preset-flow": "^7.9.0",
"@rollup/plugin-node-resolve": "^7.1.3",
"@rollup/plugin-replace": "^2.3.2",
"babel-eslint": "^10.1.0",
"babel-jest": "^25.1.0",
"babel-jest": "^25.4.0",
"babel-plugin-add-module-exports": "^1.0.2",
"babel-plugin-annotate-pure-calls": "^0.4.0",
"babel-plugin-preval": "4.0.0",
"babel-plugin-preval": "5.0.0",
"concat-stream": "^2.0.0",
"cross-env": "^7.0.2",
"cz-conventional-changelog": "^3.1.0",
"documentation": "12.1.4",
"documentation": "12.3.0",
"eslint": "^6.6.0",
"eslint-config-airbnb-base": "^14.1.0",
"eslint-plugin-import": "^2.20.1",
"flow-bin": "^0.120.1",
"eslint-plugin-import": "^2.20.2",
"flow-bin": "^0.123.0",
"flow-copy-source": "^2.0.8",
"husky": "^4.2.3",
"jest": "^25.1.0",
"lint-staged": "^10.0.8",
"husky": "^4.2.5",
"jest": "^25.4.0",
"lint-staged": "^10.1.7",
"lodash": "^4.17.15",
"npm-watch": "^0.6.0",
"prettier": "^1.18.2",
"prettier": "^2.0.5",
"pushstate-server": "3.1.0",
"ramda": "^0.27.0",
"rollup": "^2.0.6",
"rollup": "^2.7.1",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-sourcemaps": "^0.5.0",
"rollup-plugin-terser": "^5.3.0",
"rollup-plugin-uglify": "^6.0.3",
"semantic-release": "^17.0.4",
"semantic-release": "^17.0.7",
"shx": "^0.3.2",
"tsgen": "1.3.0",
"typescript": "3.8.3",
Expand Down
Loading

0 comments on commit 7886d94

Please sign in to comment.