feat: expose plugins and presets on SwaggerUI global symbol (#9189)
Part of this commit is also: - complete plugins consolidation - complete presets consolidation - build system consolidation Refs #9188
This commit is contained in:
@@ -2,14 +2,14 @@
|
||||
* @prettier
|
||||
*/
|
||||
|
||||
import path from "path"
|
||||
import deepExtend from "deep-extend"
|
||||
import webpack from "webpack"
|
||||
import TerserPlugin from "terser-webpack-plugin"
|
||||
import nodeExternals from "webpack-node-externals"
|
||||
const path = require("path")
|
||||
const deepExtend = require("deep-extend")
|
||||
const webpack = require("webpack")
|
||||
const TerserPlugin = require("terser-webpack-plugin")
|
||||
const nodeExternals = require("webpack-node-externals")
|
||||
|
||||
import { getRepoInfo } from "./_helpers"
|
||||
import pkg from "../package.json"
|
||||
const { getRepoInfo } = require("./_helpers")
|
||||
const pkg = require("../package.json")
|
||||
|
||||
const projectBasePath = path.join(__dirname, "../")
|
||||
|
||||
@@ -33,7 +33,7 @@ const baseRules = [
|
||||
},
|
||||
]
|
||||
|
||||
export default function buildConfig(
|
||||
function buildConfig(
|
||||
{
|
||||
minimize = true,
|
||||
mangle = true,
|
||||
@@ -143,6 +143,13 @@ export default function buildConfig(
|
||||
new TerserPlugin({
|
||||
terserOptions: {
|
||||
mangle: !!mangle,
|
||||
keep_classnames:
|
||||
!customConfig.mode || customConfig.mode === "production",
|
||||
keep_fnames:
|
||||
!customConfig.mode || customConfig.mode === "production",
|
||||
output: {
|
||||
comments: false,
|
||||
},
|
||||
},
|
||||
}).apply(compiler),
|
||||
],
|
||||
@@ -156,3 +163,5 @@ export default function buildConfig(
|
||||
|
||||
return completeConfig
|
||||
}
|
||||
|
||||
module.exports = buildConfig
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* @prettier
|
||||
*/
|
||||
|
||||
import { gitDescribeSync } from "git-describe"
|
||||
const { gitDescribeSync } = require("git-describe")
|
||||
|
||||
export function getRepoInfo() {
|
||||
function getRepoInfo() {
|
||||
try {
|
||||
return gitDescribeSync(__dirname)
|
||||
} catch (e) {
|
||||
@@ -15,3 +15,7 @@ export function getRepoInfo() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getRepoInfo,
|
||||
}
|
||||
|
||||
@@ -2,16 +2,19 @@
|
||||
* @prettier
|
||||
*/
|
||||
|
||||
/** Dev Note:
|
||||
/** Dev Note:
|
||||
* StatsWriterPlugin is disabled by default; uncomment to enable
|
||||
* when enabled, rebuilding the bundle will cause error for assetSizeLimit,
|
||||
* which we want to keep out of CI/CD
|
||||
* post build, cli command: npx webpack-bundle-analyzer <path>
|
||||
*/
|
||||
*/
|
||||
|
||||
const { DuplicatesPlugin } = require("inspectpack/plugin")
|
||||
const {
|
||||
WebpackBundleSizeAnalyzerPlugin,
|
||||
} = require("webpack-bundle-size-analyzer")
|
||||
const configBuilder = require("./_config-builder")
|
||||
|
||||
import configBuilder from "./_config-builder"
|
||||
import { DuplicatesPlugin } from "inspectpack/plugin"
|
||||
import { WebpackBundleSizeAnalyzerPlugin } from "webpack-bundle-size-analyzer"
|
||||
// import path from "path"
|
||||
// import { StatsWriterPlugin } from "webpack-stats-plugin"
|
||||
|
||||
@@ -24,9 +27,7 @@ const result = configBuilder(
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
"swagger-ui-bundle": [
|
||||
"./src/index.js",
|
||||
],
|
||||
"swagger-ui-bundle": ["./src/index.js"],
|
||||
},
|
||||
output: {
|
||||
globalObject: "this",
|
||||
@@ -51,4 +52,4 @@ const result = configBuilder(
|
||||
}
|
||||
)
|
||||
|
||||
export default result
|
||||
module.exports = result
|
||||
@@ -2,7 +2,7 @@
|
||||
* @prettier
|
||||
*/
|
||||
|
||||
import configBuilder from "./_config-builder"
|
||||
const configBuilder = require("./_config-builder")
|
||||
|
||||
const result = configBuilder(
|
||||
{
|
||||
@@ -13,9 +13,7 @@ const result = configBuilder(
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
"swagger-ui": [
|
||||
"./src/index.js",
|
||||
],
|
||||
"swagger-ui": ["./src/index.js"],
|
||||
},
|
||||
|
||||
output: {
|
||||
@@ -28,4 +26,4 @@ const result = configBuilder(
|
||||
}
|
||||
)
|
||||
|
||||
export default result
|
||||
module.exports = result
|
||||
@@ -2,10 +2,10 @@
|
||||
* @prettier
|
||||
*/
|
||||
|
||||
import path from "path"
|
||||
const path = require("path")
|
||||
|
||||
import configBuilder from "./_config-builder"
|
||||
import styleConfig from "./stylesheets.babel"
|
||||
const configBuilder = require("./_config-builder")
|
||||
const styleConfig = require("./stylesheets")
|
||||
|
||||
// Pretty much the same as devConfig, but with changes to port and static.directory
|
||||
const devE2eConfig = configBuilder(
|
||||
@@ -18,17 +18,15 @@ const devE2eConfig = configBuilder(
|
||||
{
|
||||
mode: "development",
|
||||
entry: {
|
||||
"swagger-ui-bundle": [
|
||||
"./src/core/index.js",
|
||||
],
|
||||
"swagger-ui-bundle": ["./src/core/index.js"],
|
||||
"swagger-ui-standalone-preset": [
|
||||
"./src/standalone/index.js",
|
||||
"./src/standalone/presets/standalone/index.js",
|
||||
],
|
||||
"swagger-ui": "./src/style/main.scss",
|
||||
},
|
||||
|
||||
performance: {
|
||||
hints: false
|
||||
hints: false,
|
||||
},
|
||||
|
||||
output: {
|
||||
@@ -61,7 +59,7 @@ const devE2eConfig = configBuilder(
|
||||
},
|
||||
devMiddleware: {},
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
// mix in the style config's plugins and loader rules
|
||||
@@ -73,4 +71,4 @@ devE2eConfig.module.rules = [
|
||||
...styleConfig.module.rules,
|
||||
]
|
||||
|
||||
export default devE2eConfig
|
||||
module.exports = devE2eConfig
|
||||
@@ -2,13 +2,15 @@
|
||||
* @prettier
|
||||
*/
|
||||
|
||||
import path from "path"
|
||||
import ReactRefreshWebpackPlugin from "@pmmmwh/react-refresh-webpack-plugin"
|
||||
import HtmlWebpackPlugin from "html-webpack-plugin"
|
||||
import { HtmlWebpackSkipAssetsPlugin } from "html-webpack-skip-assets-plugin"
|
||||
const path = require("path")
|
||||
const ReactRefreshWebpackPlugin = require("@pmmmwh/react-refresh-webpack-plugin")
|
||||
const HtmlWebpackPlugin = require("html-webpack-plugin")
|
||||
const {
|
||||
HtmlWebpackSkipAssetsPlugin,
|
||||
} = require("html-webpack-skip-assets-plugin")
|
||||
|
||||
import configBuilder from "./_config-builder"
|
||||
import styleConfig from "./stylesheets.babel"
|
||||
const configBuilder = require("./_config-builder")
|
||||
const styleConfig = require("./stylesheets")
|
||||
|
||||
const projectBasePath = path.join(__dirname, "../")
|
||||
const isDevelopment = process.env.NODE_ENV !== "production"
|
||||
@@ -23,18 +25,16 @@ const devConfig = configBuilder(
|
||||
{
|
||||
mode: "development",
|
||||
entry: {
|
||||
"swagger-ui-bundle": [
|
||||
"./src/core/index.js",
|
||||
],
|
||||
"swagger-ui-bundle": ["./src/core/index.js"],
|
||||
"swagger-ui-standalone-preset": [
|
||||
"./src/standalone/index.js",
|
||||
"./src/standalone/presets/standalone/index.js",
|
||||
],
|
||||
"swagger-ui": "./src/style/main.scss",
|
||||
vendors: ["react-refresh/runtime"],
|
||||
},
|
||||
|
||||
performance: {
|
||||
hints: false
|
||||
hints: false,
|
||||
},
|
||||
|
||||
output: {
|
||||
@@ -79,7 +79,9 @@ const devConfig = configBuilder(
|
||||
options: {
|
||||
retainLines: true,
|
||||
cacheDirectory: true,
|
||||
plugins: [isDevelopment && require.resolve("react-refresh/babel")].filter(Boolean),
|
||||
plugins: [
|
||||
isDevelopment && require.resolve("react-refresh/babel"),
|
||||
].filter(Boolean),
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -106,7 +108,7 @@ const devConfig = configBuilder(
|
||||
optimization: {
|
||||
runtimeChunk: "single", // for multiple entry points using ReactRefreshWebpackPlugin
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
// mix in the style config's plugins and loader rules
|
||||
@@ -118,4 +120,4 @@ devConfig.module.rules = [
|
||||
...styleConfig.module.rules,
|
||||
]
|
||||
|
||||
export default devConfig
|
||||
module.exports = devConfig
|
||||
@@ -2,18 +2,19 @@
|
||||
* @prettier
|
||||
*/
|
||||
|
||||
/** Dev Note:
|
||||
/** Dev Note:
|
||||
* StatsWriterPlugin is disabled by default; uncomment to enable
|
||||
* when enabled, rebuilding the bundle will cause error for assetSizeLimit,
|
||||
* which we want to keep out of CI/CD
|
||||
* post build, cli command: npx webpack-bundle-analyzer <path>
|
||||
*/
|
||||
|
||||
import configBuilder from "./_config-builder"
|
||||
import { DuplicatesPlugin } from "inspectpack/plugin"
|
||||
import { WebpackBundleSizeAnalyzerPlugin } from "webpack-bundle-size-analyzer"
|
||||
import nodeExternals from "webpack-node-externals"
|
||||
// import { StatsWriterPlugin } from "webpack-stats-plugin"
|
||||
const configBuilder = require("./_config-builder")
|
||||
const { DuplicatesPlugin } = require("inspectpack/plugin")
|
||||
const {
|
||||
WebpackBundleSizeAnalyzerPlugin,
|
||||
} = require("webpack-bundle-size-analyzer")
|
||||
const nodeExternals = require("webpack-node-externals")
|
||||
// const { StatsWriterPlugin } = require("webpack-stats-plugin")
|
||||
|
||||
const minimize = true
|
||||
const sourcemaps = true
|
||||
@@ -26,10 +27,9 @@ const result = configBuilder(
|
||||
includeDependencies: false,
|
||||
},
|
||||
{
|
||||
target: "browserslist",
|
||||
entry: {
|
||||
"swagger-ui-es-bundle-core": [
|
||||
"./src/index.js",
|
||||
],
|
||||
"swagger-ui-es-bundle-core": ["./src/index.js"],
|
||||
},
|
||||
experiments: {
|
||||
outputModule: true,
|
||||
@@ -52,11 +52,10 @@ const result = configBuilder(
|
||||
},
|
||||
nodeExternals({
|
||||
allowlist: [
|
||||
/object\/define-property/, // @babel/runtime-corejs3 import which makes fragment work with Jest
|
||||
"deep-extend", // uses Buffer as global symbol
|
||||
"randombytes", // uses require('safe-buffer')
|
||||
"sha.js", // uses require('safe-buffer')
|
||||
"xml", // uses require('stream')
|
||||
/xml/, // uses require('stream')
|
||||
/process\/browser/, // is injected via ProvidePlugin
|
||||
/readable-stream/, // byproduct of buffer ProvidePlugin injection
|
||||
"util-deprecate", // dependency of readable-stream
|
||||
@@ -68,20 +67,23 @@ const result = configBuilder(
|
||||
],
|
||||
importType: (moduleName) => {
|
||||
return `module ${moduleName}`
|
||||
}})
|
||||
},
|
||||
}),
|
||||
],
|
||||
plugins: [
|
||||
new DuplicatesPlugin({
|
||||
emitErrors: false,
|
||||
verbose: false,
|
||||
}),
|
||||
new WebpackBundleSizeAnalyzerPlugin("log.es-bundle-core-sizes.swagger-ui.txt"),
|
||||
new WebpackBundleSizeAnalyzerPlugin(
|
||||
"log.es-bundle-core-sizes.swagger-ui.txt"
|
||||
),
|
||||
// new StatsWriterPlugin({
|
||||
// filename: path.join("log.es-bundle-core-stats.swagger-ui.json"),
|
||||
// fields: null,
|
||||
// }),
|
||||
]
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
export default result
|
||||
module.exports = result
|
||||
@@ -9,9 +9,11 @@
|
||||
* post build, cli command: npx webpack-bundle-analyzer <path>
|
||||
*/
|
||||
|
||||
import configBuilder from "./_config-builder"
|
||||
import { DuplicatesPlugin } from "inspectpack/plugin"
|
||||
import { WebpackBundleSizeAnalyzerPlugin } from "webpack-bundle-size-analyzer"
|
||||
const configBuilder = require("./_config-builder")
|
||||
const { DuplicatesPlugin } = require("inspectpack/plugin")
|
||||
const {
|
||||
WebpackBundleSizeAnalyzerPlugin,
|
||||
} = require("webpack-bundle-size-analyzer")
|
||||
// import path from "path"
|
||||
// import { StatsWriterPlugin } from "webpack-stats-plugin"
|
||||
|
||||
@@ -24,9 +26,7 @@ const result = configBuilder(
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
"swagger-ui-es-bundle": [
|
||||
"./src/index.js",
|
||||
],
|
||||
"swagger-ui-es-bundle": ["./src/index.js"],
|
||||
},
|
||||
output: {
|
||||
globalObject: "this",
|
||||
@@ -47,8 +47,8 @@ const result = configBuilder(
|
||||
// filename: path.join("log.es-bundle-stats.swagger-ui.json"),
|
||||
// fields: null,
|
||||
// }),
|
||||
]
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
export default result
|
||||
module.exports = result
|
||||
@@ -2,7 +2,7 @@
|
||||
* @prettier
|
||||
*/
|
||||
|
||||
import configBuilder from "./_config-builder"
|
||||
const configBuilder = require("./_config-builder")
|
||||
|
||||
const result = configBuilder(
|
||||
{
|
||||
@@ -12,7 +12,9 @@ const result = configBuilder(
|
||||
},
|
||||
{
|
||||
entry: {
|
||||
"swagger-ui-standalone-preset": ["./src/standalone/index.js"],
|
||||
"swagger-ui-standalone-preset": [
|
||||
"./src/standalone/presets/standalone/index.js",
|
||||
],
|
||||
},
|
||||
|
||||
output: {
|
||||
@@ -25,4 +27,4 @@ const result = configBuilder(
|
||||
}
|
||||
)
|
||||
|
||||
export default result
|
||||
module.exports = result
|
||||
@@ -5,10 +5,10 @@
|
||||
// NOTE: this config *does not* inherit from `_config-builder`.
|
||||
// It is also used in the dev config.
|
||||
|
||||
import path from "path"
|
||||
import MiniCssExtractPlugin from "mini-css-extract-plugin"
|
||||
const path = require("path")
|
||||
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
|
||||
|
||||
export default {
|
||||
module.exports = {
|
||||
mode: "production",
|
||||
|
||||
entry: {
|
||||
Reference in New Issue
Block a user