Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build as ES module as well as CommonJS #120

Merged
merged 1 commit into from Oct 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions .babelrc
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
@@ -1,3 +1,4 @@
node_modules/
dist/
dist-es/
bundle.js
9 changes: 6 additions & 3 deletions package.json
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": "git@github.com: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
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -1,4 +1,4 @@
module.exports = data => {
export default data => {
const search = []

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