Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(webpack): enable SourceMaps in releases #9877

Merged
merged 6 commits into from Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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