Skip to content
This repository was archived by the owner on Sep 20, 2021. It is now read-only.

Commit b708616

Browse files
authored
Merge pull request #29 from snowcoders/k2snowman69/webpackBuild
Move to webpack build
2 parents 9e58bfb + 2f07b07 commit b708616

8 files changed

+122
-95
lines changed

package.json

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@snowcoders/react-popover",
33
"description": "Wrapper around react-popper that handles ~95% of popper scenarios",
4-
"version": "1.1.3",
4+
"version": "1.1.4",
55
"keywords": [
66
"Popper",
77
"popper.js",
@@ -21,9 +21,9 @@
2121
"main": "dist/index.js",
2222
"types": "dist/index.d.ts",
2323
"scripts": {
24-
"build": "npm run build-scss && npm run build-typescript",
24+
"build": "npm run build-scss && npm run build-webpack",
2525
"build-scss": "node-sass src/styles.scss dist/styles.css",
26-
"build-typescript": "tsc",
26+
"build-webpack": "webpack --mode production",
2727
"clean": "rimraf coverage dist",
2828
"cover": "nyc npm run test",
2929
"precommit": "lint-staged",
@@ -67,6 +67,7 @@
6767
"@types/react": "^16.4.6",
6868
"@types/react-dom": "^16.0.6",
6969
"@types/react-resize-detector": "^2.2.0",
70+
"awesome-typescript-loader": "^5.2.0",
7071
"classnames": "^2.2.6",
7172
"enzyme": "^3.3.0",
7273
"enzyme-adapter-react-16": "^1.1.1",
@@ -75,15 +76,19 @@
7576
"jsdom": "^11.12.0",
7677
"lint-staged": "^7.2.0",
7778
"node-sass": "^4.9.2",
78-
"prettier": "^1.13.7",
79-
"react": "^16.4.1",
79+
"prettier": "^1.14.0",
80+
"react": "16.4.1",
8081
"react-dom": "^16.4.1",
8182
"react-popper": "^1.0.0",
82-
"react-resize-detector": ">=2.0.0",
83+
"react-resize-detector": "^3.1.0",
8384
"rimraf": "^2.6.2",
85+
"source-map-loader": "^0.2.3",
8486
"source-map-support": "^0.5.6",
85-
"ts-jest": "^23.0.1",
87+
"ts-jest": "^23.1.2",
88+
"ts-loader": "^4.4.2",
8689
"tslib": "^1.9.3",
87-
"typescript": "^3.0.0"
90+
"typescript": "^3.0.1",
91+
"webpack": "^4.16.4",
92+
"webpack-command": "^0.4.1"
8893
}
8994
}

readme.md

+3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ To see a live example, go to our demo site https://snowcoders.github.io/react-ui
4545

4646
# Change log
4747

48+
- 1.1.4
49+
- Reduced javascript output from ~20k to ~10k by moving to webpack
50+
- Enabled resize listener for React 15
4851
- 1.1.3
4952
- Fixed initial position of popper
5053
- Disabled resize listener for React 15 due to complaints of errors

renovate.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
{
2-
"extends": [
3-
"snowcoders"
4-
]
2+
"extends": ["snowcoders"]
53
}

src/popper.blur.tsx

+7-19
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,13 @@ export class PopperBlur extends React.Component<PopperBlurProps> {
5454
data-placement={placement}
5555
onClick={this.onPopperClick}
5656
>
57-
{this.renderChildren()}
57+
<ReactResizeDetector
58+
handleHeight
59+
handleWidth
60+
onResize={this.onResize}
61+
skipOnMount
62+
/>
63+
{children}
5864
<span
5965
ref={arrowProps.ref}
6066
style={arrowProps.style}
@@ -76,24 +82,6 @@ export class PopperBlur extends React.Component<PopperBlurProps> {
7682
}
7783
};
7884

79-
private renderChildren() {
80-
const { children } = this.props;
81-
if (React.version.indexOf("15.") === 0) {
82-
return children;
83-
} else {
84-
return (
85-
<ReactResizeDetector
86-
handleHeight
87-
handleWidth
88-
onResize={this.onResize}
89-
skipOnMount
90-
>
91-
{children}
92-
</ReactResizeDetector>
93-
);
94-
}
95-
}
96-
9785
private onRef = (ref: HTMLElement | null) => {
9886
this.contentRef = ref;
9987
};

src/popper.click.tsx

+7-19
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ export class PopperClick extends React.Component<PopperClickProps> {
4343
data-placement={placement}
4444
onClick={this.onPopperClick}
4545
>
46-
{this.renderChildren()}
46+
<ReactResizeDetector
47+
handleHeight
48+
handleWidth
49+
onResize={this.onResize}
50+
skipOnMount
51+
/>
52+
{children}
4753
<span
4854
ref={arrowProps.ref}
4955
style={arrowProps.style}
@@ -65,24 +71,6 @@ export class PopperClick extends React.Component<PopperClickProps> {
6571
}
6672
};
6773

68-
private renderChildren() {
69-
const { children } = this.props;
70-
if (React.version.indexOf("15.") === 0) {
71-
return children;
72-
} else {
73-
return (
74-
<ReactResizeDetector
75-
handleHeight
76-
handleWidth
77-
onResize={this.onResize}
78-
skipOnMount
79-
>
80-
{children}
81-
</ReactResizeDetector>
82-
);
83-
}
84-
}
85-
8674
private onResize = () => {
8775
if (this.scheduleUpdate) {
8876
this.scheduleUpdate();

src/popper.hover.tsx

+7-19
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ export class PopperHover extends React.Component<
5959
style={style}
6060
data-placement={placement}
6161
>
62-
{this.renderChildren()}
62+
<ReactResizeDetector
63+
handleHeight
64+
handleWidth
65+
onResize={this.onResize}
66+
skipOnMount
67+
/>
68+
{children}
6369
<span
6470
ref={arrowProps.ref}
6571
style={arrowProps.style}
@@ -81,24 +87,6 @@ export class PopperHover extends React.Component<
8187
}
8288
};
8389

84-
private renderChildren() {
85-
const { children } = this.props;
86-
if (React.version.indexOf("15.") === 0) {
87-
return children;
88-
} else {
89-
return (
90-
<ReactResizeDetector
91-
handleHeight
92-
handleWidth
93-
onResize={this.onResize}
94-
skipOnMount
95-
>
96-
{children}
97-
</ReactResizeDetector>
98-
);
99-
}
100-
}
101-
10290
private onResize = () => {
10391
if (this.scheduleUpdate) {
10492
this.scheduleUpdate();

tsconfig.json

+21-27
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
11
{
2-
"compilerOptions": {
3-
"declaration": true,
4-
"experimentalDecorators": true,
5-
"forceConsistentCasingInFileNames": true,
6-
"importHelpers": true,
7-
"jsx": "react",
8-
"module": "commonjs",
9-
"moduleResolution": "node",
10-
"noImplicitAny": true,
11-
"noImplicitReturns": true,
12-
"noImplicitThis": true,
13-
"noUnusedLocals": false,
14-
"outDir": "./dist/",
15-
"preserveConstEnums": true,
16-
"sourceMap": true,
17-
"strictNullChecks": true,
18-
"target": "es5"
19-
},
20-
"include": [
21-
"./src/**/*.ts",
22-
"./src/**/*.tsx"
23-
],
24-
"exclude": [
25-
"./src/**/*.test.ts",
26-
"./src/**/*.test.tsx"
27-
]
28-
}
2+
"compilerOptions": {
3+
"declaration": true,
4+
"experimentalDecorators": true,
5+
"forceConsistentCasingInFileNames": true,
6+
"importHelpers": true,
7+
"jsx": "react",
8+
"module": "es6",
9+
"moduleResolution": "node",
10+
"noImplicitAny": true,
11+
"noImplicitReturns": true,
12+
"noImplicitThis": true,
13+
"noUnusedLocals": false,
14+
"outDir": "./",
15+
"preserveConstEnums": true,
16+
"sourceMap": true,
17+
"strictNullChecks": true,
18+
"target": "es5"
19+
},
20+
"include": ["./src/**/*.ts", "./src/**/*.tsx"],
21+
"exclude": ["./src/**/*.test.ts", "./src/**/*.test.tsx"]
22+
}

webpack.config.js

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// import * as webpack from "webpack";
2+
let webpack = require("webpack");
3+
const path = require("path");
4+
5+
const config /*: webpack.Configuration*/ = {
6+
entry: {
7+
main: "./src/index.ts"
8+
},
9+
output: {
10+
chunkFilename: "index.js",
11+
filename: "index.js",
12+
library: "@snowcoders/react-popover",
13+
libraryTarget: "umd",
14+
path: path.resolve(__dirname, "dist"),
15+
publicPath: "/dist/"
16+
},
17+
18+
module: {
19+
rules: [
20+
{
21+
exclude: /node_modules/,
22+
test: /\.tsx?$/,
23+
use: "ts-loader"
24+
}
25+
]
26+
},
27+
28+
resolve: {
29+
// Add '.ts' and '.tsx' as resolvable extensions.
30+
extensions: [".ts", ".tsx", ".js", ".json"]
31+
},
32+
33+
// Here is a list of our peer-dependencies that we will not include but need to have access to
34+
// Specifically because we use umd, we have to specify more information
35+
// https://stackoverflow.com/questions/34252424/webpack-umd-lib-and-external-files
36+
externals: {
37+
"@snowcoders/react-unstyled-button": "@snowcoders/react-unstyled-button",
38+
"react-dom": {
39+
amd: "react-dom",
40+
commonjs: "react-dom",
41+
commonjs2: "react-dom",
42+
root: "ReactDOM"
43+
},
44+
"react-popper": "react-popper",
45+
"react-resize-detector": {
46+
amd: "react-resize-detector",
47+
commonjs: "react-resize-detector",
48+
commonjs2: "react-resize-detector",
49+
root: "ResizeDetector"
50+
},
51+
classnames: "classnames",
52+
react: {
53+
amd: "react",
54+
commonjs: "react",
55+
commonjs2: "react",
56+
root: "React"
57+
},
58+
tslib: "tslib"
59+
}
60+
};
61+
62+
// export default config;
63+
module.exports = config;

0 commit comments

Comments
 (0)