Skip to content

Commit

Permalink
Merge pull request #120 from nolanlawson/es-modules
Browse files Browse the repository at this point in the history
Build as ES module as well as CommonJS
  • Loading branch information
EtienneLem authored Oct 4, 2017
2 parents bbd4fbe + fdc91d0 commit f8e824e
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 13 deletions.
10 changes: 8 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"transform-es2015-for-of",
"transform-es2015-function-name",
"transform-es2015-literals",
"transform-es2015-modules-commonjs",
"transform-es2015-object-super",
"transform-es2015-parameters",
"transform-es2015-shorthand-properties",
Expand Down Expand Up @@ -40,5 +39,12 @@
}
}
]
]
],
"env": {
"cjs": {
"plugins": [
"transform-es2015-modules-commonjs"
]
}
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
dist/
dist-es/
bundle.js
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "2.0.1",
"description": "Customizable Slack-like emoji picker for React",
"main": "dist/index.js",
"module": "dist-es/index.js",
"repository": {
"type": "git",
"url": "[email protected]:missive/emoji-mart.git"
Expand Down Expand Up @@ -61,11 +62,13 @@
"webpack": "^3.6.0"
},
"scripts": {
"clean": "rm -rf dist/",
"clean": "rm -rf dist/ dist-es/",
"build:data": "node scripts/build-data",
"build:dist": "npm run clean && babel src --out-dir dist --copy-files --ignore webpack.config.js",
"build:dist": "npm run clean && npm run build:cjs && npm run build:es",
"build:cjs": "BABEL_ENV=cjs babel src --out-dir dist --copy-files --ignore webpack.config.js",
"build:es": "babel src --out-dir dist-es --copy-files --ignore webpack.config.js",
"build": "npm run build:dist && npm run build:data",
"watch": "babel src --watch --out-dir dist --copy-files --ignore webpack.config.js",
"watch": "BABEL_ENV=cjs babel src --watch --out-dir dist --copy-files --ignore webpack.config.js",
"start": "npm run watch",
"stats": "webpack --config ./src/webpack.config.js --json > stats.json",
"react:clean": "rimraf node_modules/{react,react-dom,react-addons-test-utils}",
Expand Down
3 changes: 3 additions & 0 deletions scripts/build-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,7 @@ flags.emojis = flags.emojis.filter((flag) => {
const stringified = JSON.stringify(data).replace(/\"([A-Za-z_]+)\":/g, '$1:')
fs.writeFile('dist/data/data.js', `module.exports = ${stringified}`, (err) => {
if (err) throw err
fs.writeFile('dist-es/data/data.js', `export default ${stringified}`, (err) => {
if (err) throw err
})
})
4 changes: 2 additions & 2 deletions src/polyfills/createClass.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const _Object = Object

module.exports = function createClass() {
export default (function createClass() {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
Expand All @@ -16,4 +16,4 @@ module.exports = function createClass() {
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
}());
2 changes: 1 addition & 1 deletion src/polyfills/extends.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const _Object = Object

module.exports = _Object.assign || function (target) {
export default _Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];

Expand Down
2 changes: 1 addition & 1 deletion src/polyfills/inherits.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const _Object = Object

module.exports = function inherits(subClass, superClass) {
export default function inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
Expand Down
2 changes: 1 addition & 1 deletion src/polyfills/objectGetPrototypeOf.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const _Object = Object

module.exports = _Object.getPrototypeOf || function (O) {
export default _Object.getPrototypeOf || function (O) {
O = Object(O)

if (typeof O.constructor === 'function' && O instanceof O.constructor) {
Expand Down
2 changes: 1 addition & 1 deletion src/polyfills/possibleConstructorReturn.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function possibleConstructorReturn(self, call) {
export default function possibleConstructorReturn(self, call) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
Expand Down
2 changes: 1 addition & 1 deletion src/polyfills/stringFromCodePoint.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const _String = String

module.exports = _String.fromCodePoint || function stringFromCodePoint() {
export default _String.fromCodePoint || function stringFromCodePoint() {
var MAX_SIZE = 0x4000;
var codeUnits = [];
var highSurrogate;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/build-search.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = data => {
export default data => {
const search = []

var addToSearch = (strings, split) => {
Expand Down

0 comments on commit f8e824e

Please sign in to comment.