Skip to content
This repository has been archived by the owner on Dec 31, 2020. It is now read-only.

Commit

Permalink
Revert use of TSDX
Browse files Browse the repository at this point in the history
It will be included in upcoming 2.0 as it's a breaking change
  • Loading branch information
danielkcz committed Aug 24, 2019
1 parent 34bf321 commit c19b013
Show file tree
Hide file tree
Showing 8 changed files with 390 additions and 2,094 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Expand Up @@ -4,9 +4,6 @@ dist/
coverage/

.rpt2_cache
.rts2_cache_cjs
.rts2_cache_esm
.rts2_cache_umd
.DS_Store

npm-debug.log*
Expand Down
1 change: 0 additions & 1 deletion .npmignore
Expand Up @@ -3,7 +3,6 @@
src/
test/
coverage/
dist/test

.vscode
.rpt2_cache
Expand Down
10 changes: 2 additions & 8 deletions .size-limit.json
@@ -1,13 +1,7 @@
[
{
"path": "dist/mobxreactlite.umd.production.min.js",
"limit": "1.6 KB",
"webpack": false,
"running": false
},
{
"path": "dist/mobxreactlite.cjs.production.min.js",
"limit": "1.6 KB",
"path": "dist/index.js",
"limit": "4 KB",
"webpack": false,
"running": false
}
Expand Down
98 changes: 98 additions & 0 deletions build-rollup.js
@@ -0,0 +1,98 @@
var path = require("path")
var filesize = require("rollup-plugin-filesize")
var typescript = require("rollup-plugin-typescript2")
var commonjs = require("rollup-plugin-commonjs")
var resolve = require("rollup-plugin-node-resolve")
var terser = require("rollup-plugin-terser").terser
var alias = require("rollup-plugin-alias")
var replace = require("rollup-plugin-replace")

var { rollup } = require("rollup")

var emptyModulePath = path.resolve(__dirname, "empty.js")

function getExternals(target) {
switch (target) {
case "browser":
return ["react", "mobx", "react-dom"]
case "native":
return ["react", "mobx", "react-native"]
case "custom":
return ["react", "mobx"]
}
}

function getAliases(target) {
switch (target) {
case "browser":
return { "react-native": emptyModulePath }
case "native":
return { "react-dom": emptyModulePath }
case "custom":
return { "react-native": emptyModulePath, "react-dom": emptyModulePath }
}
}

function build(target, mode, filename) {
var plugins = [
replace({
// for depencencies such as react-is
"process.env.NODE_ENV": JSON.stringify("production")
}),
alias({ "react-native": emptyModulePath }),
typescript({
tsconfig: "tsconfig.build.json",
clean: true,
check: true,
useTsconfigDeclarationDir: true
}),
resolve({
module: true,
main: true
}),
commonjs()
]

if (mode.endsWith(".min")) {
plugins.push(terser())
}

plugins.push(filesize())

return rollup({
input: "src/index.ts",
external: getExternals(target),
plugins: plugins
})
.then(function(bundle) {
var options = {
file: path.resolve(__dirname, "dist", filename),
format: mode.endsWith(".min") ? mode.slice(0, -".min".length) : mode,
globals: {
react: "React",
"react-dom": "ReactDOM",
"react-native": "ReactNative",
mobx: "mobx"
},
name: "mobxReactLite",
exports: "named"
}

return bundle.write(options)
})
.catch(function(reason) {
console.error(reason)
process.exit(-1)
})
}

const main = async () => {
await build("browser", "umd", "index.js")
await build("browser", "umd.min", "index.min.js")
await build("browser", "es", "index.module.js")
await build("native", "cjs", "native.js")
await build("custom", "umd", "custom.js")
await build("custom", "es", "custom.module.js")
}

main()
3 changes: 3 additions & 0 deletions empty.js
@@ -0,0 +1,3 @@
// These functions can be stubbed out in specific environments
export const unstable_batchedUpdates = undefined
export const findDOMNode = undefined
21 changes: 13 additions & 8 deletions package.json
Expand Up @@ -3,12 +3,11 @@
"version": "1.4.1",
"description": "Lightweight React bindings for MobX based on React 16.8 and Hooks",
"main": "dist/index.js",
"jsnext:main": "dist/index.module.js",
"module": "dist/index.module.js",
"react-native": "dist/native.js",
"typings": "dist/index.d.ts",
"types": "dist/index.d.ts",
"jsnext:main": "dist/mobxreactlite.esm.js",
"module": "dist/mobxreactlite.esm.js",
"unpkg": "dist/mobxreactlite.umd.production.min.js",
"react-native": "dist/mobxreactlite.esm.js",
"repository": {
"type": "git",
"url": "https://github.com/mobxjs/mobx-react-lite.git"
Expand All @@ -22,8 +21,7 @@
"size": "size-limit",
"coverage": "jest --coverage",
"prebuild": "rimraf dist",
"build": "yarn bundle",
"bundle": "tsdx build --name mobxReactLite --format=cjs,esm,umd",
"build": "node build-rollup.js",
"prepublishOnly": "yarn build"
},
"author": "Daniel K.",
Expand Down Expand Up @@ -58,9 +56,16 @@
"react-dom": "16.8.6",
"react-test-renderer": "16.8.6",
"rimraf": "3.0.0",
"rollup": "1.20.1",
"rollup-plugin-alias": "1.5.2",
"rollup-plugin-commonjs": "10.0.2",
"rollup-plugin-filesize": "6.2.0",
"rollup-plugin-node-resolve": "5.2.0",
"rollup-plugin-replace": "2.2.0",
"rollup-plugin-terser": "5.1.1",
"rollup-plugin-typescript2": "0.23.0",
"size-limit": "2.1.1",
"ts-jest": "24.0.2",
"tsdx": "0.8.0",
"tslint": "5.19.0",
"tslint-config-prettier": "1.18.0",
"typescript": "3.4.5"
Expand All @@ -75,7 +80,7 @@
"hooks",
"observer",
"useObserver",
"useComputed"
"useComputer"
],
"lint-staged": {
"*.{ts,js}": [
Expand Down
10 changes: 10 additions & 0 deletions tsconfig.build.json
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": true,
"declarationDir": "dist",
"sourceMap": true
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}

0 comments on commit c19b013

Please sign in to comment.