Skip to content
This repository was archived by the owner on Jun 2, 2024. It is now read-only.

Commit d8c836d

Browse files
authored
Adds rollup (#5)
* Adds rollup
1 parent 57ff1aa commit d8c836d

File tree

7 files changed

+165
-21
lines changed

7 files changed

+165
-21
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
# testing
55

66
# production
7-
/dist
7+
/lib
8+
/build
89

910
# workspace
1011
.vscode
@@ -15,6 +16,7 @@
1516
.env.development.local
1617
.env.test.local
1718
.env.production.local
19+
.rpt2_cache
1820
npm-debug.log*
1921
yarn-debug.log*
2022
yarn-error.log*

package-lock.json

Lines changed: 95 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
"type": "git",
88
"url": "https://github.com/csvenke/react-semantics.git"
99
},
10-
"main": "dist/index.js",
11-
"types": "dist/index.d.ts",
10+
"main": "lib/index.min.js",
11+
"types": "lib/types/index.d.ts",
1212
"files": [
13-
"dist"
13+
"lib/index.min.js",
14+
"lib/types/index.d.ts",
15+
"lib/types/components"
1416
],
1517
"private": false,
1618
"license": "MIT",
@@ -43,18 +45,23 @@
4345
"react-dom": "^16.4.1",
4446
"react": "^16.4.1",
4547
"rimraf": "^2.6.2",
48+
"rollup-plugin-typescript2": "^0.16.1",
49+
"rollup-plugin-uglify": "^4.0.0",
50+
"rollup": "^0.63.4",
4651
"ts-jest": "^23.0.1",
4752
"tslint-config-prettier": "^1.14.0",
4853
"tslint-plugin-prettier": "^1.3.0",
4954
"tslint": "^5.11.0",
5055
"typescript": "^2.9.2"
5156
},
5257
"scripts": {
53-
"build": "npm run clean:build && npm run lint && npm run prettify && npm run test && tsc -p ./tsconfig.build.json",
54-
"clean:build": "rimraf ./dist",
55-
"lint": "tslint -c tslint.json './src/**/*'",
56-
"lintfix": "tslint -c tslint.json --fix './src/**/*'",
57-
"prettify": "prettier -c .prettierrc --write \"src/**/*.@(ts|tsx)\"",
58+
"build": "npm run clean:build && npm run lint && npm run test && rollup -c",
59+
"clean:build": "rimraf ./lib",
60+
"lint": "npm run lint:write './src/**/*'",
61+
"lint:fix": "npm run lint:write --fix './src/**/*'",
62+
"lint:write": "tslint -c tslint.json",
63+
"prettier": "npm run prettier:write \"src/**/*.@(ts|tsx)\"",
64+
"prettier:write": "prettier -c .prettierrc --write",
5865
"test": "jest"
5966
},
6067
"husky": {
@@ -77,7 +84,7 @@
7784
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
7885
"testPathIgnorePatterns": [
7986
"<rootDir>/node_modules/",
80-
"<rootDir>/dist/"
87+
"<rootDir>/lib/"
8188
],
8289
"setupTestFrameworkScriptFile": "<rootDir>/src/setupTests.ts",
8390
"moduleFileExtensions": [

rollup.config.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import typescript from 'rollup-plugin-typescript2';
2+
import { uglify } from 'rollup-plugin-uglify';
3+
import pkg from './package.json';
4+
5+
const externals = [
6+
...(Object.keys(pkg.dependencies) || {}),
7+
...(Object.keys(pkg.peerDependencies) || {}),
8+
];
9+
10+
const createConfig = ({ output } = {}) => ({
11+
input: 'src/index.ts',
12+
output,
13+
external: externals,
14+
plugins: [
15+
typescript({
16+
useTsconfigDeclarationDir: true,
17+
tsconfig: './tsconfig.build.json',
18+
typescript: require('typescript'),
19+
}),
20+
uglify(),
21+
],
22+
});
23+
24+
export default [
25+
createConfig({
26+
output: {
27+
file: pkg.main,
28+
format: 'cjs',
29+
},
30+
}),
31+
];

src/components/Switch/Switch.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import * as PropTypes from 'prop-types';
22
import * as React from 'react';
33

44
import SwitchCase, { ISwitchCaseProps } from './SwitchCase';
5-
import SwitchDefault from './SwitchDefault';
5+
import SwitchDefault, { ISwitchDefaultProps } from './SwitchDefault';
6+
7+
type SwitchChildProps = ISwitchCaseProps & ISwitchDefaultProps;
68

79
export interface ISwitchProps {
810
/** Conditional statement. */
@@ -46,7 +48,7 @@ class Switch extends React.Component<ISwitchProps> {
4648

4749
React.Children.forEach(
4850
this.props.children,
49-
(element: React.ReactElement<ISwitchCaseProps>) => {
51+
(element: React.ReactElement<SwitchChildProps>) => {
5052
if (match === undefined && React.isValidElement(element)) {
5153
const caseValue = element.props.value;
5254
child = element;

tsconfig.build.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
{
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
4-
"outDir": "dist",
4+
"outDir": "./lib",
55
"sourceMap": false,
66
"declaration": true,
7-
"removeComments": false
7+
"removeComments": false,
8+
"declarationDir": "lib/types"
89
},
9-
"include": ["src/**/*"],
10-
"exclude": ["node_modules"]
10+
"include": [
11+
"src/index.ts",
12+
"src/components/**/index.ts"
13+
],
14+
"exclude": [
15+
"src/**/*.test.ts",
16+
"src/**/*.test.tsx"
17+
]
1118
}

tsconfig.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compileOnSave": false,
33
"compilerOptions": {
4-
"outDir": "./dist/out",
4+
"outDir": "./build",
55
"baseUrl": ".",
66
"typeRoots": ["./node_modules/@types"],
77
"target": "es5",
@@ -12,8 +12,9 @@
1212
"sourceMap": true,
1313
"allowSyntheticDefaultImports": false,
1414
"noUnusedLocals": true,
15-
"noUnusedParameters": true,
16-
"removeComments": false
15+
"noUnusedParameters": true
1716
},
18-
"exclude": ["node_modules", "dist"]
17+
"include": [
18+
"src/**/*"
19+
]
1920
}

0 commit comments

Comments
 (0)