Skip to content

Commit

Permalink
Rewrite build steps and update output
Browse files Browse the repository at this point in the history
- Updated all "build:x" scripts based on React-Redux package
- Added tsconfig and TS types output, and moved TS output to ./es
- Added Babel compilation of TS syntax
  • Loading branch information
markerikson committed Oct 17, 2021
1 parent f51d54b commit f2dcde3
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 21 deletions.
17 changes: 14 additions & 3 deletions .babelrc.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
const { BABEL_ENV, NODE_ENV } = process.env
const cjs = BABEL_ENV === 'cjs' || NODE_ENV === 'test'
const { NODE_ENV, BABEL_ENV } = process.env
const cjs = NODE_ENV === 'test' || BABEL_ENV === 'commonjs'

module.exports = {
presets: [
['@babel/env', { loose: true, modules: cjs ? 'cjs' : false }]
[
'@babel/preset-env',
{
targets: {
ie: 11
},
loose: true,
modules: cjs ? 'cjs' : false
}
],
'@babel/preset-typescript'
],
plugins: [cjs && ['@babel/transform-modules-commonjs']].filter(Boolean)
}
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lib
es
dist
node_modules
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ typescript_test/should_not_compile/index.js
typescript_test/common.js
flow_test/should_fail/flow-typed/index.js.flow
flow_test/should_pass/flow-typed/index.js.flow
reselect-builds/
27 changes: 16 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"name": "reselect",
"version": "4.1.0-alpha.0",
"description": "Selectors for Redux.",
"main": "lib/index.js",
"jsnext:main": "es/index.js",
"module": "es/index.js",
"typings": "lib/index.d.ts",
"main": "./lib/index.js",
"jsnext:main": "./es/index.js",
"module": "./es/index.js",
"types": "./es/index.d.ts",
"unpkg": "./dist/reselect.js",
"typesVersions": {
"<4.2.0": {
"*": [
Expand All @@ -23,13 +24,17 @@
"url": "https://github.com/reduxjs/reselect/issues"
},
"scripts": {
"compile:commonjs": "better-npm-run compile:commonjs",
"compile:umdmin": "uglifyjs dist/reselect.js -mt -o dist/reselect.min.js",
"compile:umd": "rollup -c",
"compile:es": "babel -d es/ src/",
"compile": "npm run compile:commonjs && npm run compile:umd && npm run compile:umdmin && npm run compile:es",
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src/index.ts --extensions .ts --out-dir lib ",
"build:es": "babel src/index.ts --extensions .ts --out-dir es",
"build:umd": "cross-env NODE_ENV=development rollup -c -o dist/reselect.js",
"build:umd:min": "cross-env NODE_ENV=production rollup -c -o dist/reselect.min.js",
"build:types": "tsc",
"build": "rimraf dist lib es && npm run build:types && npm run build:commonjs && npm run build:es && npm run build:umd && npm run build:umd:min",
"clean": "rimraf lib dist es coverage",
"api-types": "api-extractor run --local",
"format": "prettier --write \"{src,test}/**/*.{js,ts}\" \"docs/**/*.md\"",
"lint": "eslint src test",
"prepublish": "npm run compile",
"prepare": "npm run build",
"test": "better-npm-run test",
"test:cov": "better-npm-run test:cov",
"test:typescript": "better-npm-run test:typescript"
Expand All @@ -52,7 +57,7 @@
"command": "tsc --noEmit -p typescript_test/tsconfig.json"
},
"compile:commonjs": {
"command": "babel -d lib/ src/ && ncp ./src/index.d.ts ./lib/index.d.ts",
"command": "babel -d lib/ src/",
"env": {
"BABEL_ENV": "cjs"
}
Expand Down
43 changes: 38 additions & 5 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,48 @@
import nodeResolve from '@rollup/plugin-node-resolve'
import babel from '@rollup/plugin-babel'
import replace from '@rollup/plugin-replace'
import commonjs from '@rollup/plugin-commonjs'
import { terser } from 'rollup-plugin-terser'

export default {
input: 'src/index.js',
const env = process.env.NODE_ENV

const extensions = ['.js', '.ts', '.tsx', '.json']

const config = {
input: 'src/index.ts',
output: {
file: 'dist/reselect.js',
format: 'umd',
name: 'Reselect'
},
plugins: [
nodeResolve({
extensions
}),
babel({
babelHelpers: 'bundled'
})
include: 'src/**/*',
exclude: '**/node_modules/**',
babelHelpers: 'bundled',
extensions
}),
replace({
'process.env.NODE_ENV': JSON.stringify(env),
preventAssignment: true
}),
commonjs()
]
}

if (env === 'production') {
config.plugins.push(
terser({
compress: {
pure_getters: true,
unsafe: true,
unsafe_comps: true,
warnings: false
}
})
)
}

export default config
12 changes: 10 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {
import type {
Selector,
GetParamsFromSelectors,
OutputSelector,
Expand All @@ -7,7 +7,15 @@ import {
SelectorResultArray
} from './types'

export * from './types'
export type {
Selector,
GetParamsFromSelectors,
OutputSelector,
EqualityFn,
SelectorArray,
SelectorResultArray,
ParametricSelector
} from './types'

export const defaultEqualityCheck: EqualityFn = (a, b) => {
return a === b
Expand Down
21 changes: 21 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"strict": true,
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Node",
"esModuleInterop": true,
"skipLibCheck": true,
"allowJs": true,
"jsx": "react",
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "./es",
"forceConsistentCasingInFileNames": true,
"experimentalDecorators": true,
"rootDirs": ["./src", "./test"],
"rootDir": "./src",
},
"include": ["src/**/*", "typescript-test/**/*"],
"exclude": ["node_modules", "dist"]
}

0 comments on commit f2dcde3

Please sign in to comment.