Skip to content

Commit 8be2828

Browse files
committed
update dependencies to latest and cleanup webpack
1 parent 840f11b commit 8be2828

File tree

8 files changed

+4643
-5547
lines changed

8 files changed

+4643
-5547
lines changed

.babelrc

Lines changed: 0 additions & 25 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to loose [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [1.1.0] - 2022-09-28
8+
### Changed
9+
- Updated build tools and demo dependencies to latest versions.
10+
- Updated webpack to output significantly smaller build.
11+
- Removed an unnecessary lodash dependency that could be handled natively.
12+
713
## [1.0.0] - 2020-10-23
814
### Changed
915
- Bumped to version 1 after months of testing with various scenarios.

babel.config.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module.exports = {
2+
presets: [
3+
// check https://github.com/babel/babel/blob/main/packages/babel-preset-env/src/available-plugins.ts to see which plugins are included in preset-env
4+
['@babel/preset-env',
5+
{ corejs: '3.25', useBuiltIns: 'entry', debug: false },
6+
],
7+
'@babel/preset-react',
8+
],
9+
plugins: [
10+
['@babel/plugin-proposal-decorators',
11+
{ legacy: true },
12+
], // required for mobx decorators. Must come above class-properties
13+
['@babel/plugin-proposal-class-properties',
14+
{ loose: false },
15+
], // required for mobx decorators
16+
'@babel/plugin-syntax-import-meta',
17+
'@babel/plugin-proposal-function-sent',
18+
'@babel/plugin-proposal-throw-expressions',
19+
'@babel/plugin-proposal-export-default-from',
20+
['@babel/plugin-proposal-pipeline-operator',
21+
{ proposal: 'minimal' },
22+
],
23+
'@babel/plugin-proposal-do-expressions',
24+
'@babel/plugin-proposal-function-bind',
25+
],
26+
env: {
27+
test: {
28+
plugins: ['@babel/plugin-transform-runtime'],
29+
},
30+
},
31+
};

package.json

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"name": "react-nested-popper",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "A react library based on popper.js that supports nested poppers and proper context binding.",
55
"main": "dist/lib.js",
66
"scripts": {
77
"build": "webpack --mode=production",
8+
"build-dev": "webpack --mode=development",
89
"start": "webpack-dev-server --mode=development",
910
"deploy": "gh-pages -d dist",
1011
"post-deploy": "rm dist/demo.css dist/demo.js dist/index.html",
@@ -37,8 +38,8 @@
3738
},
3839
"homepage": "https://github.com/runfaj/react-nested-popper#readme",
3940
"peerDependencies": {
40-
"react": "^16.x",
41-
"react-dom": "^16.x"
41+
"react": ">=16.x",
42+
"react-dom": ">=16.x"
4243
},
4344
"dependencies": {
4445
"@popperjs/core": "^2.5.3",
@@ -71,13 +72,13 @@
7172
"@babel/plugin-transform-runtime": "^7.8.3",
7273
"@babel/preset-env": "^7.0.0",
7374
"@babel/preset-react": "^7.0.0",
74-
"autoprefixer": "^9.7.4",
75+
"autoprefixer": "^10.4.0",
7576
"babel-eslint": "^10.0.3",
7677
"babel-jest": "^25.1.0",
7778
"babel-loader": "^8.0.6",
78-
"clean-webpack-plugin": "^3.0.0",
79-
"css-loader": "^3.4.2",
80-
"cssnano": "^4.1.10",
79+
"clean-webpack-plugin": "^4.0.0",
80+
"css-loader": "^6.5.1",
81+
"cssnano": "^5.0.10",
8182
"enzyme": "^3.11.0",
8283
"enzyme-adapter-react-16": "^1.15.2",
8384
"eslint": "^6.8.0",
@@ -88,20 +89,21 @@
8889
"eslint-plugin-jsx-a11y": "^6.2.3",
8990
"eslint-plugin-react": "^7.18.0",
9091
"gh-pages": "^2.2.0",
91-
"html-webpack-plugin": "^3.2.0",
92+
"html-webpack-plugin": "^5.5.0",
9293
"jest": "^25.1.0",
9394
"jquery": "^3.4.1",
94-
"mini-css-extract-plugin": "^0.9.0",
95-
"node-sass": "^4.13.1",
96-
"postcss-loader": "^3.0.0",
95+
"mini-css-extract-plugin": "^2.4.4",
96+
"postcss-loader": "^6.2.0",
97+
"progress-webpack-plugin": "^1.0.16",
9798
"react": "^16.12.0",
9899
"react-addons-test-utils": "^15.6.2",
99100
"react-dom": "^16.12.0",
100101
"react-test-renderer": "^16.12.0",
101-
"sass-loader": "^8.0.2",
102-
"terser-webpack-plugin": "^2.3.3",
103-
"webpack": "^4.41.5",
104-
"webpack-cli": "^3.3.10",
105-
"webpack-dev-server": "^3.10.1"
102+
"sass": "^1.55.0",
103+
"sass-loader": "^12.3.0",
104+
"webpack": "^5.64.1",
105+
"webpack-bundle-analyzer": "^4.6.1",
106+
"webpack-cli": "^4.9.1",
107+
"webpack-dev-server": "^4.5.0"
106108
}
107109
}

src/Target.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
import _omit from 'lodash/omit';
43

54
export default class Target extends React.Component {
65
static className = 'react-nested-popper_Target';
@@ -11,25 +10,33 @@ export default class Target extends React.Component {
1110
so we enforce this component.
1211
*/
1312
setRef(el) {
14-
if (this.props.innerRef) {
15-
this.props.innerRef(el);
13+
const { innerRef, _targetRef } = this.props;
14+
if (innerRef) {
15+
innerRef(el);
1616
}
17-
if (this.props._targetRef) {
18-
this.props._targetRef(el);
17+
if (_targetRef) {
18+
_targetRef(el);
1919
}
2020
}
2121

2222
render() {
23-
const rest = _omit(this.props, Object.keys(Target.propTypes));
23+
const {
24+
children,
25+
className,
26+
_onClick,
27+
innerRef,
28+
_targetRef,
29+
...rest
30+
} = this.props;
2431

2532
return (
2633
<div
27-
className={this.props.className}
34+
className={className}
2835
ref={el => this.setRef(el)}
29-
onClick={this.props._onClick}
36+
onClick={_onClick}
3037
{...rest}
3138
>
32-
{this.props.children}
39+
{children}
3340
</div>
3441
);
3542
}

src/index.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
/* eslint-disable import/prefer-default-export */
22

3-
import Popper from './Popper';
4-
import Target from './Target';
5-
import Content from './Content';
6-
import Stack from './Stack';
7-
8-
export {
9-
Popper,
10-
Target,
11-
Content,
12-
Stack,
13-
};
3+
export Popper from './Popper';
4+
export Target from './Target';
5+
export Content from './Content';
6+
export Stack from './Stack';

webpack.config.js

Lines changed: 39 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,18 @@
22
const path = require('path');
33
const HtmlWebpackPlugin = require('html-webpack-plugin');
44
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
5-
const TerserPlugin = require('terser-webpack-plugin');
65
const AutoPrefixerPlugin = require('autoprefixer');
76
const CSSNanoPlugin = require('cssnano');
87
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
8+
const ProgressPlugin = require('progress-webpack-plugin');
9+
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
910

10-
const { NODE_ENV = 'development' } = process.env;
11-
const useProductionBuild = NODE_ENV === 'production';
12-
13-
module.exports = {
14-
mode: useProductionBuild ? 'production' : 'development',
15-
devtool: useProductionBuild ? 'source-map' : 'cheap-module-eval-source-map',
16-
stats: 'errors-only',
11+
const config = {
1712
devServer: {
1813
compress: true,
19-
contentBase: false,
2014
historyApiFallback: true,
2115
hot: true,
2216
port: 8765,
23-
stats: {
24-
assets: false,
25-
children: false,
26-
chunkModules: false,
27-
chunks: false,
28-
colors: true,
29-
hash: false,
30-
version: false,
31-
modules: false,
32-
warningsFilter: warning => !_.contains(warning, 'WARNING in chunk') && !_.contains(warning, 'Conflicting order between'),
33-
},
3417
},
3518
entry: {
3619
lib: path.resolve(__dirname, 'src/index.js'),
@@ -42,32 +25,6 @@ module.exports = {
4225
pathinfo: false,
4326
libraryTarget: 'umd',
4427
},
45-
optimization: (!useProductionBuild
46-
? {
47-
removeAvailableModules: false,
48-
removeEmptyChunks: false,
49-
splitChunks: false,
50-
}
51-
: {
52-
splitChunks: {
53-
cacheGroups: {
54-
peerDependencies: {
55-
test: /[\\/]node_modules[\\/]react(-dom)?[\\/]/,
56-
},
57-
},
58-
},
59-
minimizer: [
60-
new TerserPlugin({
61-
sourceMap: true,
62-
terserOptions: {
63-
output: {
64-
comments: false,
65-
},
66-
},
67-
}),
68-
],
69-
}
70-
),
7128
module: {
7229
rules: [
7330
{
@@ -81,7 +38,7 @@ module.exports = {
8138
{
8239
loader: MiniCssExtractPlugin.loader,
8340
options: {
84-
hmr: !useProductionBuild,
41+
esModule: false,
8542
},
8643
},
8744
{
@@ -97,12 +54,13 @@ module.exports = {
9754
{
9855
loader: 'postcss-loader',
9956
options: {
100-
plugins: [
101-
AutoPrefixerPlugin,
102-
CSSNanoPlugin,
103-
],
57+
postcssOptions: {
58+
plugins: [
59+
AutoPrefixerPlugin,
60+
CSSNanoPlugin,
61+
],
62+
},
10463
sourceMap: true,
105-
modules: true,
10664
},
10765
},
10866
{
@@ -117,13 +75,40 @@ module.exports = {
11775
},
11876
plugins: [
11977
new CleanWebpackPlugin(),
120-
78+
new ProgressPlugin(true),
12179
new MiniCssExtractPlugin({
12280
filename: '[name].css',
12381
}),
124-
12582
new HtmlWebpackPlugin({
12683
template: './demo/index.template.html',
12784
}),
85+
// new BundleAnalyzerPlugin(),
12886
],
12987
};
88+
89+
module.exports = (env, argv) => {
90+
if (argv.mode === 'development') {
91+
config.devtool = 'eval-cheap-module-source-map';
92+
config.optimization = {
93+
removeAvailableModules: false,
94+
removeEmptyChunks: false,
95+
splitChunks: false,
96+
};
97+
} else {
98+
config.devtool = 'source-map';
99+
config.optimization = {
100+
chunkIds: 'total-size',
101+
minimize: true,
102+
moduleIds: 'size',
103+
splitChunks: {
104+
cacheGroups: {
105+
peerDependencies: {
106+
test: /[\\/]node_modules[\\/]react(-dom)?[\\/]/,
107+
},
108+
},
109+
},
110+
};
111+
}
112+
113+
return config;
114+
};

0 commit comments

Comments
 (0)