Skip to content

Commit

Permalink
fix: distribute proper source maps in npm distribution packages (#9877)
Browse files Browse the repository at this point in the history
Refs #9101
  • Loading branch information
glowcloud committed Apr 30, 2024
1 parent b6805e5 commit 8c90d5d
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 17 deletions.
3 changes: 0 additions & 3 deletions .npmignore
Expand Up @@ -6,11 +6,8 @@
!dist/swagger-ui.js
!dist/swagger-ui.js.map
!dist/swagger-ui-bundle.js
!dist/swagger-ui-bundle.js.map
!dist/swagger-ui-standalone-preset.js
!dist/swagger-ui-standalone-preset.js.map
!dist/swagger-ui-es-bundle.js
!dist/swagger-ui-es-bundle.js.map
!dist/swagger-ui-es-bundle-core.js
!dist/swagger-ui-es-bundle-core.js.map
!dist/swagger-ui.css
Expand Down
2 changes: 0 additions & 2 deletions flavors/swagger-ui-react/release/run.sh
Expand Up @@ -14,9 +14,7 @@ cp ../../../dist/swagger-ui-es-bundle-core.js.map ../dist
cp ../../../dist/swagger-ui.js ../dist
cp ../../../dist/swagger-ui.js.map ../dist
cp ../../../dist/swagger-ui-bundle.js ../dist
cp ../../../dist/swagger-ui-bundle.js.map ../dist
cp ../../../dist/swagger-ui-es-bundle.js ../dist
cp ../../../dist/swagger-ui-es-bundle.js.map ../dist
cp ../../../dist/swagger-ui.css ../dist
cp ../../../dist/swagger-ui.css.map ../dist

Expand Down
11 changes: 3 additions & 8 deletions webpack/_config-builder.js
Expand Up @@ -8,7 +8,7 @@ const webpack = require("webpack")
const TerserPlugin = require("terser-webpack-plugin")
const nodeExternals = require("webpack-node-externals")

const { getRepoInfo } = require("./_helpers")
const { getRepoInfo, getDevtool } = require("./_helpers")
const pkg = require("../package.json")

const projectBasePath = path.join(__dirname, "../")
Expand Down Expand Up @@ -129,13 +129,7 @@ function buildConfig(
},
},

// If we're mangling, size is a concern -- so use trace-only sourcemaps
// Otherwise, provide heavy souremaps suitable for development
devtool: sourcemaps
? minimize
? "nosources-source-map"
: "cheap-module-source-map"
: false,
devtool: getDevtool(sourcemaps, minimize),

performance: {
hints: "error",
Expand All @@ -149,6 +143,7 @@ function buildConfig(
(compiler) =>
new TerserPlugin({
terserOptions: {
sourceMap: sourcemaps,
mangle: !!mangle,
keep_classnames:
!customConfig.mode || customConfig.mode === "production",
Expand Down
6 changes: 6 additions & 0 deletions webpack/_helpers.js
Expand Up @@ -16,6 +16,12 @@ function getRepoInfo() {
}
}

function getDevtool(sourcemaps, minimize) {
if (!sourcemaps) return false
return minimize ? "source-map" : "cheap-module-source-map"
}

module.exports = {
getRepoInfo,
getDevtool,
}
2 changes: 1 addition & 1 deletion webpack/bundle.js
Expand Up @@ -22,7 +22,7 @@ const result = configBuilder(
{
minimize: true,
mangle: true,
sourcemaps: true,
sourcemaps: false,
includeDependencies: true,
},
{
Expand Down
3 changes: 2 additions & 1 deletion webpack/es-bundle-core.js
Expand Up @@ -14,6 +14,7 @@ const {
WebpackBundleSizeAnalyzerPlugin,
} = require("webpack-bundle-size-analyzer")
const nodeExternals = require("webpack-node-externals")
const { getDevtool } = require("./_helpers")
// const { StatsWriterPlugin } = require("webpack-stats-plugin")

const minimize = true
Expand Down Expand Up @@ -44,7 +45,7 @@ const result = configBuilder(
module: true,
},
},
devtool: sourcemaps && minimize ? "source-map" : false,
devtool: getDevtool(sourcemaps, minimize),
externalsType: "module",
externals: [
{
Expand Down
2 changes: 1 addition & 1 deletion webpack/es-bundle.js
Expand Up @@ -21,7 +21,7 @@ const result = configBuilder(
{
minimize: true,
mangle: true,
sourcemaps: true,
sourcemaps: false,
includeDependencies: true,
},
{
Expand Down
2 changes: 1 addition & 1 deletion webpack/standalone.js
Expand Up @@ -8,7 +8,7 @@ const result = configBuilder(
{
minimize: true,
mangle: true,
sourcemaps: true,
sourcemaps: false,
},
{
entry: {
Expand Down

0 comments on commit 8c90d5d

Please sign in to comment.