From 8873fc56d305b890913d0303f3a377dcd523a72a Mon Sep 17 00:00:00 2001 From: awmleer Date: Wed, 18 Sep 2019 15:58:19 +0800 Subject: [PATCH] add umd build --- gulpfile.js | 24 ++++++++++++-- package.json | 9 ++++-- rollup.config.js | 15 +++++++++ tsconfig.json | 6 ++-- yarn.lock | 84 +++++++++++++++++++++++++++++++++++++++++++++--- 5 files changed, 125 insertions(+), 13 deletions(-) create mode 100644 rollup.config.js diff --git a/gulpfile.js b/gulpfile.js index b0ea75e..c213320 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,13 +1,31 @@ const gulp = require('gulp') const del = require('del') +const rollupConfig = require('./rollup.config') +const rollup = require('rollup') +const ts = require('gulp-typescript') -gulp.task('clean-lib', function (callback) { +const tsProject = ts.createProject('tsconfig.json') + +gulp.task('clean-lib', function(callback) { del('lib/**') callback() }) -gulp.task('prebuild', gulp.series('clean-lib', function() { +gulp.task('copy-files', function() { return gulp .src(['package.json', 'README.md', 'LICENSE']) .pipe(gulp.dest('lib/')) -})) +}) + +gulp.task('ts', function(callback) { + return tsProject.src() + .pipe(tsProject()) + .pipe(gulp.dest('lib')) +}) + +gulp.task('rollup', async function(callback) { + const bundle = await rollup.rollup(rollupConfig) + return await bundle.write(rollupConfig.output) +}) + +gulp.task('build', gulp.series('clean-lib', 'copy-files', 'ts', 'rollup')) diff --git a/package.json b/package.json index e461f59..424809d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "reto", - "version": "0.3.1", + "version": "0.4.0", "main": "index.js", "repository": "https://github.com/awmleer/reto", "description": "React store with hooks.", @@ -11,9 +11,10 @@ "react": "^16.8.0" }, "scripts": { - "build": "gulp prebuild && tsc", + "build": "gulp build", "test": "jest", - "lint": "tslint -p tsconfig.json" + "lint": "tslint -p tsconfig.json", + "umd": "rollup --config rollup.config.js" }, "devDependencies": { "@testing-library/jest-dom": "^4.0.0", @@ -25,10 +26,12 @@ "@types/react-test-renderer": "^16.8.0", "del": "^5.0.0", "gulp": "^4.0.2", + "gulp-typescript": "^5.0.1", "jest": "^24.1.0", "react": "^16.8.0", "react-dom": "^16.8.0", "react-test-renderer": "^16.8.0", + "rollup": "^1.21.4", "ts-jest": "^24.0.2", "tslint": "^5.18.0", "typescript": "^3.4.5" diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..c5d7353 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,15 @@ +module.exports = { + external: [ + 'react', + 'reflect-metadata', + ], + input: 'lib/index.js', + output: { + name: 'reto', + globals: { + react: 'React' + }, + file: 'lib/umd/reto.js', + format: 'umd' + } +} diff --git a/tsconfig.json b/tsconfig.json index cadb736..a81abd0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,8 +3,10 @@ "sourceMap": false, "declaration": true, "noImplicitAny": true, - "target": "es5", - "module": "commonjs", + "target": "es6", + "module": "esnext", + "moduleResolution": "node", + "esModuleInterop": true, "jsx": "react", "lib": ["es6"], "outDir": "./lib" diff --git a/yarn.lock b/yarn.lock index 6684b51..c5b9812 100644 --- a/yarn.lock +++ b/yarn.lock @@ -392,6 +392,11 @@ dependencies: "@babel/types" "^7.3.0" +"@types/estree@0.0.39": + version "0.0.39" + resolved "https://registry.npm.taobao.org/@types/estree/download/@types/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f" + integrity sha1-4Xfmme4bjCLSMXTKqnQiZEOJUJ8= + "@types/events@*": version "3.0.0" resolved "https://registry.npm.taobao.org/@types/events/download/@types/events-3.0.0.tgz?cache=0&sync_timestamp=1567532284800&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40types%2Fevents%2Fdownload%2F%40types%2Fevents-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7" @@ -443,7 +448,7 @@ resolved "https://registry.npm.taobao.org/@types/minimatch/download/@types/minimatch-3.0.3.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40types%2Fminimatch%2Fdownload%2F%40types%2Fminimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d" integrity sha1-PcoOPzOyAPx9ETnAzZbBJoyt/Z0= -"@types/node@*": +"@types/node@*", "@types/node@^12.7.5": version "12.7.5" resolved "https://registry.npm.taobao.org/@types/node/download/@types/node-12.7.5.tgz#e19436e7f8e9b4601005d73673b6dc4784ffcc2f" integrity sha1-4ZQ25/jptGAQBdc2c7bcR4T/zC8= @@ -530,6 +535,11 @@ acorn@^6.0.1: resolved "https://registry.npm.taobao.org/acorn/download/acorn-6.3.0.tgz#0087509119ffa4fc0a0041d1e93a417e68cb856e" integrity sha1-AIdQkRn/pPwKAEHR6TpBfmjLhW4= +acorn@^7.0.0: + version "7.0.0" + resolved "https://registry.npm.taobao.org/acorn/download/acorn-7.0.0.tgz#26b8d1cd9a9b700350b71c0905546f64d1284e7a" + integrity sha1-JrjRzZqbcANQtxwJBVRvZNEoTno= + aggregate-error@^3.0.0: version "3.0.0" resolved "https://registry.npm.taobao.org/aggregate-error/download/aggregate-error-3.0.0.tgz#5b5a3c95e9095f311c9ab16c19fb4f3527cd3f79" @@ -555,6 +565,11 @@ ansi-colors@^1.0.1: dependencies: ansi-wrap "^0.1.0" +ansi-colors@^3.0.5: + version "3.2.4" + resolved "https://registry.npm.taobao.org/ansi-colors/download/ansi-colors-3.2.4.tgz#e3a3da4bfbae6c86a9c285625de124a234026fbf" + integrity sha1-46PaS/uubIapwoViXeEkojQCb78= + ansi-escapes@^3.0.0: version "3.2.0" resolved "https://registry.npm.taobao.org/ansi-escapes/download/ansi-escapes-3.2.0.tgz#8780b98ff9dbf5638152d1f1fe5c1d7b4442976b" @@ -2022,6 +2037,18 @@ gulp-cli@^2.2.0: v8flags "^3.0.1" yargs "^7.1.0" +gulp-typescript@^5.0.1: + version "5.0.1" + resolved "https://registry.npm.taobao.org/gulp-typescript/download/gulp-typescript-5.0.1.tgz#96c6565a6eb31e08c2aae1c857b1a079e6226d94" + integrity sha1-lsZWWm6zHgjCquHIV7GgeeYibZQ= + dependencies: + ansi-colors "^3.0.5" + plugin-error "^1.0.1" + source-map "^0.7.3" + through2 "^3.0.0" + vinyl "^2.1.0" + vinyl-fs "^3.0.3" + gulp@^4.0.2: version "4.0.2" resolved "https://registry.npm.taobao.org/gulp/download/gulp-4.0.2.tgz#543651070fd0f6ab0a0650c6a3e6ff5a7cb09caa" @@ -3802,6 +3829,16 @@ pkg-dir@^3.0.0: dependencies: find-up "^3.0.0" +plugin-error@^1.0.1: + version "1.0.1" + resolved "https://registry.npm.taobao.org/plugin-error/download/plugin-error-1.0.1.tgz#77016bd8919d0ac377fdcdd0322328953ca5781c" + integrity sha1-dwFr2JGdCsN3/c3QMiMolTyleBw= + dependencies: + ansi-colors "^1.0.1" + arr-diff "^4.0.0" + arr-union "^3.1.0" + extend-shallow "^3.0.2" + pn@^1.1.0: version "1.1.0" resolved "https://registry.npm.taobao.org/pn/download/pn-1.1.0.tgz#e2f4cef0e219f463c179ab37463e4e1ecdccbafb" @@ -3977,6 +4014,15 @@ read-pkg@^3.0.0: normalize-package-data "^2.3.2" path-type "^3.0.0" +"readable-stream@2 || 3": + version "3.4.0" + resolved "https://registry.npm.taobao.org/readable-stream/download/readable-stream-3.4.0.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Freadable-stream%2Fdownload%2Freadable-stream-3.4.0.tgz#a51c26754658e0a3c21dbf59163bd45ba6f447fc" + integrity sha1-pRwmdUZY4KPCHb9ZFjvUW6b0R/w= + dependencies: + inherits "^2.0.3" + string_decoder "^1.1.1" + util-deprecate "^1.0.1" + readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.5, readable-stream@^2.0.6, readable-stream@^2.1.5, readable-stream@^2.2.2, readable-stream@^2.3.3, readable-stream@^2.3.5, readable-stream@^2.3.6, readable-stream@~2.3.6: version "2.3.6" resolved "https://registry.npm.taobao.org/readable-stream/download/readable-stream-2.3.6.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Freadable-stream%2Fdownload%2Freadable-stream-2.3.6.tgz#b11c27d88b8ff1fbe070643cf94b0c79ae1b0aaf" @@ -4210,6 +4256,15 @@ rimraf@^3.0.0: dependencies: glob "^7.1.3" +rollup@^1.21.4: + version "1.21.4" + resolved "https://registry.npm.taobao.org/rollup/download/rollup-1.21.4.tgz#00a41a30f90095db890301b226cbe2918e4cf54d" + integrity sha1-AKQaMPkAlduJAwGyJsvikY5M9U0= + dependencies: + "@types/estree" "0.0.39" + "@types/node" "^12.7.5" + acorn "^7.0.0" + rsvp@^4.8.4: version "4.8.5" resolved "https://registry.npm.taobao.org/rsvp/download/rsvp-4.8.5.tgz#c8f155311d167f68f21e168df71ec5b083113734" @@ -4220,7 +4275,7 @@ run-parallel@^1.1.9: resolved "https://registry.npm.taobao.org/run-parallel/download/run-parallel-1.1.9.tgz#c9dd3a7cf9f4b2c4b6244e173a6ed866e61dd679" integrity sha1-yd06fPn0ssS2JE4XOm7YZuYd1nk= -safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.2: +safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.2, safe-buffer@~5.2.0: version "5.2.0" resolved "https://registry.npm.taobao.org/safe-buffer/download/safe-buffer-5.2.0.tgz?cache=0&sync_timestamp=1562377642757&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fsafe-buffer%2Fdownload%2Fsafe-buffer-5.2.0.tgz#b74daec49b1148f88c64b68d49b1e815c1f2f519" integrity sha1-t02uxJsRSPiMZLaNSbHoFcHy9Rk= @@ -4403,6 +4458,11 @@ source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.1: resolved "https://registry.npm.taobao.org/source-map/download/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" integrity sha1-dHIq8y6WFOnCh6jQu95IteLxomM= +source-map@^0.7.3: + version "0.7.3" + resolved "https://registry.npm.taobao.org/source-map/download/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383" + integrity sha1-UwL4FpAxc1ImVECS5kmB91F1A4M= + sparkles@^1.0.0: version "1.0.1" resolved "https://registry.npm.taobao.org/sparkles/download/sparkles-1.0.1.tgz#008db65edce6c50eec0c5e228e1945061dd0437c" @@ -4544,6 +4604,13 @@ string.prototype.trimright@^2.0.0: define-properties "^1.1.3" function-bind "^1.1.1" +string_decoder@^1.1.1: + version "1.3.0" + resolved "https://registry.npm.taobao.org/string_decoder/download/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e" + integrity sha1-QvEUWUpGzxqOMLCoT1bHjD7awh4= + dependencies: + safe-buffer "~5.2.0" + string_decoder@~1.1.1: version "1.1.1" resolved "https://registry.npm.taobao.org/string_decoder/download/string_decoder-1.1.1.tgz#9cf1611ba62685d7030ae9e4ba34149c3af03fc8" @@ -4672,6 +4739,13 @@ through2@^2.0.0, through2@^2.0.3, through2@~2.0.0: readable-stream "~2.3.6" xtend "~4.0.1" +through2@^3.0.0: + version "3.0.1" + resolved "https://registry.npm.taobao.org/through2/download/through2-3.0.1.tgz#39276e713c3302edf9e388dd9c812dd3b825bd5a" + integrity sha1-OSducTwzAu3544jdnIEt07glvVo= + dependencies: + readable-stream "2 || 3" + time-stamp@^1.0.0: version "1.1.0" resolved "https://registry.npm.taobao.org/time-stamp/download/time-stamp-1.1.0.tgz#764a5a11af50561921b133f3b44e618687e0f5c3" @@ -4923,7 +4997,7 @@ use@^3.1.0: resolved "https://registry.npm.taobao.org/use/download/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f" integrity sha1-1QyMrHmhn7wg8pEfVuuXP04QBw8= -util-deprecate@~1.0.1: +util-deprecate@^1.0.1, util-deprecate@~1.0.1: version "1.0.2" resolved "https://registry.npm.taobao.org/util-deprecate/download/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8= @@ -4970,7 +5044,7 @@ verror@1.10.0: core-util-is "1.0.2" extsprintf "^1.2.0" -vinyl-fs@^3.0.0: +vinyl-fs@^3.0.0, vinyl-fs@^3.0.3: version "3.0.3" resolved "https://registry.npm.taobao.org/vinyl-fs/download/vinyl-fs-3.0.3.tgz#c85849405f67428feabbbd5c5dbdd64f47d31bc7" integrity sha1-yFhJQF9nQo/qu71cXb3WT0fTG8c= @@ -5006,7 +5080,7 @@ vinyl-sourcemap@^1.1.0: remove-bom-buffer "^3.0.0" vinyl "^2.0.0" -vinyl@^2.0.0: +vinyl@^2.0.0, vinyl@^2.1.0: version "2.2.0" resolved "https://registry.npm.taobao.org/vinyl/download/vinyl-2.2.0.tgz#d85b07da96e458d25b2ffe19fece9f2caa13ed86" integrity sha1-2FsH2pbkWNJbL/4Z/s6fLKoT7YY=