From 6161d333366fa719d8bcf657d83f4d90ce9e49a4 Mon Sep 17 00:00:00 2001 From: Jimmy Jia Date: Sat, 28 Mar 2020 16:26:55 -0400 Subject: [PATCH] chore: Add ES module build (#370) * chore: Add ES module build * nit --- .babelrc | 16 -------- .babelrc.js | 18 +++++++++ .eslintignore | 4 ++ .eslintrc | 15 ------- .eslintrc.js | 10 +++++ .gitignore | 101 +++++++++++++++++++++++++++++++++++++++++++--- package.json | 9 ++++- test/.eslintrc | 13 ------ test/.eslintrc.js | 16 ++++++++ 9 files changed, 150 insertions(+), 52 deletions(-) delete mode 100644 .babelrc create mode 100644 .babelrc.js delete mode 100644 .eslintrc create mode 100644 .eslintrc.js delete mode 100644 test/.eslintrc create mode 100644 test/.eslintrc.js diff --git a/.babelrc b/.babelrc deleted file mode 100644 index be55c9b..0000000 --- a/.babelrc +++ /dev/null @@ -1,16 +0,0 @@ -{ - "presets": [ - ["@4c", { - "targets": {} - }] - ], - "plugins": [ - "add-module-exports" - ], - - "env": { - "test": { - "plugins": ["istanbul"] - } - } -} diff --git a/.babelrc.js b/.babelrc.js new file mode 100644 index 0000000..a758a81 --- /dev/null +++ b/.babelrc.js @@ -0,0 +1,18 @@ +module.exports = (api) => ({ + presets: [ + [ + '@4c', + { + targets: {}, + modules: api.env() === 'esm' ? false : 'commonjs', + }, + ], + ], + plugins: [api.env() !== 'esm' && 'add-module-exports'].filter(Boolean), + + env: { + test: { + plugins: ['istanbul'], + }, + }, +}); diff --git a/.eslintignore b/.eslintignore index 4ce3705..650391d 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,7 @@ +!.babelrc.js +!.eslintrc.js + **/coverage/ **/lib/ +**/es/ **/node_modules/ diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 8bb2170..0000000 --- a/.eslintrc +++ /dev/null @@ -1,15 +0,0 @@ -{ - "extends": [ - "4catalyzer", - "prettier" - ], - "plugins": [ - "prettier" - ], - "env": { - "browser": true - }, - "rules": { - "prettier/prettier": "error" - } -} diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..40f0cd8 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,10 @@ +module.exports = { + extends: ['4catalyzer', 'prettier'], + plugins: ['prettier'], + env: { + browser: true, + }, + rules: { + 'prettier/prettier': 'error', + }, +}; diff --git a/.gitignore b/.gitignore index 6392f42..590d1c3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,30 +1,119 @@ # Logs logs *.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json # Runtime data pids *.pid *.seed +*.pid.lock # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage +*.lcov + +# nyc test coverage +.nyc_output -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) .grunt +# Bower dependency directory (https://bower.io/) +bower_components + # node-waf configuration .lock-wscript -# Compiled binary addons (http://nodejs.org/api/addons.html) +# Compiled binary addons (https://nodejs.org/api/addons.html) build/Release -# Dependency directory -# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git -node_modules +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 + +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.pnp.* -# Transpiled code +# Transpiled code. /lib +/es diff --git a/package.json b/package.json index 8d93073..9ddcb9c 100644 --- a/package.json +++ b/package.json @@ -3,12 +3,17 @@ "version": "0.10.0", "description": "Pluggable browser scroll management", "files": [ - "lib" + "lib", + "es" ], "main": "lib/index.js", + "module": "es/index.js", "types": "lib/index.d.ts", "scripts": { - "build": "babel src -d lib --delete-dir-on-start && cpy types/*.d.ts lib", + "build": "npm run build:cjs && npm run build:esm && npm run build:types", + "build:cjs": "babel -d lib --delete-dir-on-start src", + "build:esm": "babel --env-name esm -d es --delete-dir-on-start src", + "build:types": "cpy types/*.d.ts lib", "format": "eslint --fix . && npm run prettier -- --write", "lint": "eslint . && npm run prettier -- -l", "prepublish": "npm run build", diff --git a/test/.eslintrc b/test/.eslintrc deleted file mode 100644 index aa17fe1..0000000 --- a/test/.eslintrc +++ /dev/null @@ -1,13 +0,0 @@ -{ - "env": { - "mocha": true - }, - "globals": { - "expect": false - }, - "rules": { - "import/no-extraneous-dependencies": ["error", { - "devDependencies": true - }] - } -} diff --git a/test/.eslintrc.js b/test/.eslintrc.js new file mode 100644 index 0000000..7334bf7 --- /dev/null +++ b/test/.eslintrc.js @@ -0,0 +1,16 @@ +module.exports = { + env: { + mocha: true, + }, + globals: { + expect: false, + }, + rules: { + 'import/no-extraneous-dependencies': [ + 'error', + { + devDependencies: true, + }, + ], + }, +};