diff --git a/make-webpack-config.js b/make-webpack-config.js index c8e5dbee..74eae669 100644 --- a/make-webpack-config.js +++ b/make-webpack-config.js @@ -52,6 +52,7 @@ module.exports = function(rules, options) { hot: false, separateStylesheets: true, minimize: false, + mangle: false, longTermCaching: false, sourcemaps: false, }, options._special) @@ -69,6 +70,10 @@ module.exports = function(rules, options) { plugins.push( new UglifyJsPlugin({ + uglifyOptions: { + mangle: specialOptions.mangle, + beautify: !specialOptions.mangle, + }, sourceMap: true, }), new webpack.LoaderOptionsPlugin({ diff --git a/src/core/components/online-validator-badge.jsx b/src/core/components/online-validator-badge.jsx index 3878b29c..e9c251cb 100644 --- a/src/core/components/online-validator-badge.jsx +++ b/src/core/components/online-validator-badge.jsx @@ -1,6 +1,9 @@ import React from "react" +import URL from "url-parse" + import PropTypes from "prop-types" import { sanitizeUrl } from "core/utils" +import win from "core/window" export default class OnlineValidatorBadge extends React.Component { static propTypes = { @@ -11,20 +14,28 @@ export default class OnlineValidatorBadge extends React.Component { constructor(props, context) { super(props, context) - let { specSelectors, getConfigs } = props + let { getConfigs } = props let { validatorUrl } = getConfigs() this.state = { - url: specSelectors.url(), + url: this.getDefinitionUrl(), validatorUrl: validatorUrl === undefined ? "https://online.swagger.io/validator" : validatorUrl } } + getDefinitionUrl = () => { + // TODO: test this behavior by stubbing `window.location` in an Enzyme/JSDom env + let { specSelectors } = this.props + + const urlObject = new URL(specSelectors.url(), win.location) + return urlObject.toString() + } + componentWillReceiveProps(nextProps) { - let { specSelectors, getConfigs } = nextProps + let { getConfigs } = nextProps let { validatorUrl } = getConfigs() this.setState({ - url: specSelectors.url(), + url: this.getDefinitionUrl(), validatorUrl: validatorUrl === undefined ? "https://online.swagger.io/validator" : validatorUrl }) } diff --git a/webpack-dist-bundle.config.js b/webpack-dist-bundle.config.js index 48b39be3..5872c1ed 100644 --- a/webpack-dist-bundle.config.js +++ b/webpack-dist-bundle.config.js @@ -20,6 +20,7 @@ module.exports = require("./make-webpack-config.js")(rules, { _special: { separateStylesheets: true, minimize: true, + mangle: true, sourcemaps: true, }, diff --git a/webpack-dist-standalone.config.js b/webpack-dist-standalone.config.js index 22477a9f..3f16b5dd 100644 --- a/webpack-dist-standalone.config.js +++ b/webpack-dist-standalone.config.js @@ -20,6 +20,7 @@ module.exports = require("./make-webpack-config.js")(rules, { _special: { separateStylesheets: true, minimize: true, + mangle: true, sourcemaps: true, },