Skip to content

Commit

Permalink
fix uglify cannot work bug. didnt use constructor name to judge compo…
Browse files Browse the repository at this point in the history
…nent
  • Loading branch information
ctxhou committed Dec 2, 2017
1 parent 3ba0862 commit da79d1b
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 56 deletions.
8 changes: 0 additions & 8 deletions Tabs.test.js

This file was deleted.

14 changes: 7 additions & 7 deletions dist/react-tabtab.es.js
Expand Up @@ -619,7 +619,7 @@ var TabListComponent = function (_React$Component) {
_this.toggleModal = _this.toggleModal.bind(_this);
_this.renderTabs = _this.renderTabs.bind(_this);
_this.isShowModalButton = _this.isShowModalButton.bind(_this);
_this.isShowArrowButton = _this.isShowArrowButton.bind(_this);
// (this: any).isShowArrowButton = this.isShowArrowButton.bind(this);
_this.scrollPosition = 0;
_this.tabRefs = [];
_this.state = {
Expand Down Expand Up @@ -657,11 +657,12 @@ var TabListComponent = function (_React$Component) {
}, {
key: 'getTabNode',
value: function getTabNode(tab) {
var tabType = tab.constructor.name;
if (tabType === 'Tab') {
if (tab.__INTERNAL_NODE) {
// normal tab
return tab.__INTERNAL_NODE;
} else if (tabType === 'DragTab') {
return tab.__INTERNAL_NODE.node;
} else if (tab.__DRAG_TAB_INTERNAL_NODE) {
// drag tab
return tab.__DRAG_TAB_INTERNAL_NODE.node;
}
}
}, {
Expand Down Expand Up @@ -746,7 +747,6 @@ var TabListComponent = function (_React$Component) {
showArrowButton = false;
for (var index = 0; index < this.tabRefs.length; index++) {
var tab = this.getTabNode(this.tabRefs[index]);
// $FlowFixMe
tabWidth += tab.offsetWidth;
if (tabWidth >= containerWidth) {
showArrowButton = true;
Expand Down Expand Up @@ -1069,7 +1069,7 @@ var DragTab = function (_React$Component) {
return createElement(
DragTabElement,
_extends({ ref: function ref(node) {
return _this2.__INTERNAL_NODE = node;
return _this2.__DRAG_TAB_INTERNAL_NODE = node;
} }, props),
children
);
Expand Down
2 changes: 1 addition & 1 deletion dist/react-tabtab.min.js

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions package.json
Expand Up @@ -13,7 +13,7 @@
"test:watch": "NODE_ENV=test npm test -- --watch",
"flow": "flow check",
"flow:watch": "flow-watch",
"gh-pages": "rimraf _gh-pages && gh-pages:build && gh-pages:publish",
"gh-pages": "rimraf _gh-pages && npm run gh-pages:build && npm run gh-pages:publish",
"gh-pages:build": "cross-env NODE_ENV=production webpack --config webpack.config.prod.js",
"gh-pages:publish": "git-directory-deploy --directory _gh-pages --branch gh-pages",
"prepublish": "npm run build",
Expand Down Expand Up @@ -110,8 +110,7 @@
"rollup-plugin-replace": "^2.0.0",
"rollup-plugin-uglify": "^2.0.1",
"rollup-plugin-visualizer": "^0.3.1",
"uglify-js": "git://github.com/mishoo/UglifyJS2#harmony-v2.8.22",
"uglifyjs-webpack-plugin": "1.0.1",
"uglifyjs-webpack-plugin": "^1.1.2",
"webpack": "^3.3.0",
"webpack-bundle-analyzer": "^2.9.0",
"webpack-dev-middleware": "^1.12.0",
Expand Down Expand Up @@ -140,4 +139,4 @@
"lint",
"test"
]
}
}
2 changes: 1 addition & 1 deletion rollup.config.js
Expand Up @@ -63,7 +63,7 @@ const plugins = [

if (prod) {
plugins.push(
// uglify(),
uglify(),
visualizer({filename: './bundle-stats.html'}),
replace({
'process.env.NODE_ENV': JSON.stringify(prod ? 'production' : 'development'),
Expand Down
4 changes: 2 additions & 2 deletions src/DragTab.js
Expand Up @@ -17,12 +17,12 @@ type Props = {

class DragTab extends React.Component<Props> {

__INTERNAL_NODE: React.ElementRef<any>;
__DRAG_TAB_INTERNAL_NODE: React.ElementRef<any>;

render() {
const {children, ...props} = this.props;
return (
<DragTabElement ref={node => this.__INTERNAL_NODE = node} {...props}>
<DragTabElement ref={node => this.__DRAG_TAB_INTERNAL_NODE = node} {...props}>
{children}
</DragTabElement>
)
Expand Down
10 changes: 4 additions & 6 deletions src/TabList.js
Expand Up @@ -123,7 +123,7 @@ export default class TabListComponent extends React.Component<Props, State> {
(this: any).toggleModal = this.toggleModal.bind(this);
(this: any).renderTabs = this.renderTabs.bind(this);
(this: any).isShowModalButton = this.isShowModalButton.bind(this);
(this: any).isShowArrowButton = this.isShowArrowButton.bind(this);
// (this: any).isShowArrowButton = this.isShowArrowButton.bind(this);
(this: any).scrollPosition = 0;
(this: any).tabRefs = [];
(this: any).state = {
Expand Down Expand Up @@ -157,11 +157,10 @@ export default class TabListComponent extends React.Component<Props, State> {
}

getTabNode(tab: any): React.ElementRef<any> {
const tabType = tab.constructor.name;
if (tabType === 'Tab') {
if (tab.__INTERNAL_NODE) { // normal tab
return tab.__INTERNAL_NODE;
} else if (tabType === 'DragTab') {
return tab.__INTERNAL_NODE.node;
} else if (tab.__DRAG_TAB_INTERNAL_NODE) { // drag tab
return tab.__DRAG_TAB_INTERNAL_NODE.node;
}
}

Expand Down Expand Up @@ -235,7 +234,6 @@ export default class TabListComponent extends React.Component<Props, State> {
showArrowButton = false;
for (let index = 0; index < this.tabRefs.length; index++) {
const tab = this.getTabNode(this.tabRefs[index]);
// $FlowFixMe
tabWidth += tab.offsetWidth;
if (tabWidth >= containerWidth) {
showArrowButton = true;
Expand Down
4 changes: 3 additions & 1 deletion webpack.config.prod.js
@@ -1,6 +1,7 @@
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
entry: {
Expand Down Expand Up @@ -40,7 +41,8 @@ module.exports = {
trackingId: 'UA-54035195-6',
pageViewOnLoad: true
}
})
}),
new UglifyJSPlugin()
],
module: {
loaders: [
Expand Down
47 changes: 21 additions & 26 deletions yarn.lock
Expand Up @@ -1450,6 +1450,10 @@ commander@2.11.x, commander@^2.11.0, commander@^2.9.0, commander@~2.11.0:
version "2.11.0"
resolved "https://registry.npmjs.org/commander/-/commander-2.11.0.tgz#157152fd1e7a6c8d98a5b715cf376df928004563"

commander@~2.12.1:
version "2.12.2"
resolved "https://registry.npmjs.org/commander/-/commander-2.12.2.tgz#0f5946c427ed9ec0d91a46bb9def53e54650e555"

commondir@^1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
Expand Down Expand Up @@ -5372,7 +5376,7 @@ source-map@^0.4.4:
dependencies:
amdefine ">=0.0.4"

source-map@~0.6.1:
source-map@^0.6.1, source-map@~0.6.1:
version "0.6.1"
resolved "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"

Expand Down Expand Up @@ -5729,11 +5733,11 @@ ua-parser-js@^0.7.9:
version "0.7.17"
resolved "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.17.tgz#e9ec5f9498b9ec910e7ae3ac626a805c4d09ecac"

uglify-es@^3.1.3:
version "3.1.9"
resolved "https://registry.npmjs.org/uglify-es/-/uglify-es-3.1.9.tgz#6c82df628ac9eb7af9c61fd70c744a084abe6161"
uglify-es@^3.2.0:
version "3.2.0"
resolved "https://registry.npmjs.org/uglify-es/-/uglify-es-3.2.0.tgz#fbbfb9dc465ec7e5065701b9720d0de977d0bc24"
dependencies:
commander "~2.11.0"
commander "~2.12.1"
source-map "~0.6.1"

uglify-js@3.1.x, uglify-js@^3.0.9:
Expand All @@ -5752,31 +5756,10 @@ uglify-js@^2.6, uglify-js@^2.8.29:
optionalDependencies:
uglify-to-browserify "~1.0.0"

"uglify-js@git://github.com/mishoo/UglifyJS2#harmony-v2.8.22":
version "2.8.22"
resolved "git://github.com/mishoo/UglifyJS2#278577f3cb75e72320564805ee91be63e5f9c806"
dependencies:
source-map "~0.5.1"
yargs "~3.10.0"
optionalDependencies:
uglify-to-browserify "~1.0.0"

uglify-to-browserify@~1.0.0:
version "1.0.2"
resolved "https://registry.npmjs.org/uglify-to-browserify/-/uglify-to-browserify-1.0.2.tgz#6e0924d6bda6b5afe349e39a6d632850a0f882b7"

uglifyjs-webpack-plugin@1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/uglifyjs-webpack-plugin/-/uglifyjs-webpack-plugin-1.0.1.tgz#d324da7144d321202df0968c09f6f8e057d5cdc2"
dependencies:
cacache "^10.0.0"
find-cache-dir "^1.0.0"
schema-utils "^0.3.0"
source-map "^0.5.6"
uglify-es "^3.1.3"
webpack-sources "^1.0.1"
worker-farm "^1.4.1"

uglifyjs-webpack-plugin@^0.4.6:
version "0.4.6"
resolved "https://registry.npmjs.org/uglifyjs-webpack-plugin/-/uglifyjs-webpack-plugin-0.4.6.tgz#b951f4abb6bd617e66f63eb891498e391763e309"
Expand All @@ -5785,6 +5768,18 @@ uglifyjs-webpack-plugin@^0.4.6:
uglify-js "^2.8.29"
webpack-sources "^1.0.1"

uglifyjs-webpack-plugin@^1.1.2:
version "1.1.2"
resolved "https://registry.npmjs.org/uglifyjs-webpack-plugin/-/uglifyjs-webpack-plugin-1.1.2.tgz#8a9abc238d01a33daaf86fa9a84c7ebc1e67b0f9"
dependencies:
cacache "^10.0.0"
find-cache-dir "^1.0.0"
schema-utils "^0.3.0"
source-map "^0.6.1"
uglify-es "^3.2.0"
webpack-sources "^1.0.1"
worker-farm "^1.4.1"

uid-number@^0.0.6:
version "0.0.6"
resolved "https://registry.npmjs.org/uid-number/-/uid-number-0.0.6.tgz#0ea10e8035e8eb5b8e4449f06da1c730663baa81"
Expand Down

0 comments on commit da79d1b

Please sign in to comment.