feat(build): expose true ESM bundle as primary artifact (#7937)
Refs #7907 Refs #7831
This commit is contained in:
@@ -4,4 +4,5 @@ module.exports = {
|
|||||||
rootDir: path.join(__dirname, '..', '..'),
|
rootDir: path.join(__dirname, '..', '..'),
|
||||||
testEnvironment: 'jsdom',
|
testEnvironment: 'jsdom',
|
||||||
testMatch: ['**/test/build-artifacts/**/*.js'],
|
testMatch: ['**/test/build-artifacts/**/*.js'],
|
||||||
|
transformIgnorePatterns: ['/node_modules/(?!(swagger-client|react-syntax-highlighter)/)'],
|
||||||
};
|
};
|
||||||
|
|||||||
18
package-lock.json
generated
18
package-lock.json
generated
@@ -6,7 +6,7 @@
|
|||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "swagger-ui",
|
"name": "swagger-ui",
|
||||||
"version": "4.8.0",
|
"version": "4.8.1",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime-corejs3": "^7.16.8",
|
"@babel/runtime-corejs3": "^7.16.8",
|
||||||
@@ -128,6 +128,7 @@
|
|||||||
"webpack-bundle-size-analyzer": "^3.1.0",
|
"webpack-bundle-size-analyzer": "^3.1.0",
|
||||||
"webpack-cli": "^4.9.2",
|
"webpack-cli": "^4.9.2",
|
||||||
"webpack-dev-server": "^4.7.4",
|
"webpack-dev-server": "^4.7.4",
|
||||||
|
"webpack-node-externals": "=3.0.0",
|
||||||
"webpack-stats-plugin": "=1.0.3"
|
"webpack-stats-plugin": "=1.0.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -24883,6 +24884,15 @@
|
|||||||
"node": ">=10.0.0"
|
"node": ">=10.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/webpack-node-externals": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/webpack-node-externals/-/webpack-node-externals-3.0.0.tgz",
|
||||||
|
"integrity": "sha512-LnL6Z3GGDPht/AigwRh2dvL9PQPFQ8skEpVrWZXLWBYmqcaojHNN0onvHzie6rq7EWKrrBfPYqNEzTJgiwEQDQ==",
|
||||||
|
"dev": true,
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/webpack-stats-plugin": {
|
"node_modules/webpack-stats-plugin": {
|
||||||
"version": "1.0.3",
|
"version": "1.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/webpack-stats-plugin/-/webpack-stats-plugin-1.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/webpack-stats-plugin/-/webpack-stats-plugin-1.0.3.tgz",
|
||||||
@@ -44207,6 +44217,12 @@
|
|||||||
"wildcard": "^2.0.0"
|
"wildcard": "^2.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"webpack-node-externals": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/webpack-node-externals/-/webpack-node-externals-3.0.0.tgz",
|
||||||
|
"integrity": "sha512-LnL6Z3GGDPht/AigwRh2dvL9PQPFQ8skEpVrWZXLWBYmqcaojHNN0onvHzie6rq7EWKrrBfPYqNEzTJgiwEQDQ==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"webpack-stats-plugin": {
|
"webpack-stats-plugin": {
|
||||||
"version": "1.0.3",
|
"version": "1.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/webpack-stats-plugin/-/webpack-stats-plugin-1.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/webpack-stats-plugin/-/webpack-stats-plugin-1.0.3.tgz",
|
||||||
|
|||||||
@@ -180,6 +180,7 @@
|
|||||||
"webpack-bundle-size-analyzer": "^3.1.0",
|
"webpack-bundle-size-analyzer": "^3.1.0",
|
||||||
"webpack-cli": "^4.9.2",
|
"webpack-cli": "^4.9.2",
|
||||||
"webpack-dev-server": "^4.7.4",
|
"webpack-dev-server": "^4.7.4",
|
||||||
|
"webpack-node-externals": "=3.0.0",
|
||||||
"webpack-stats-plugin": "=1.0.3"
|
"webpack-stats-plugin": "=1.0.3"
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
|
|||||||
@@ -3,16 +3,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import fs from "fs"
|
|
||||||
import deepExtend from "deep-extend"
|
import deepExtend from "deep-extend"
|
||||||
import webpack from "webpack"
|
import webpack from "webpack"
|
||||||
import TerserPlugin from "terser-webpack-plugin"
|
import TerserPlugin from "terser-webpack-plugin"
|
||||||
|
import nodeExternals from "webpack-node-externals"
|
||||||
|
|
||||||
import { getRepoInfo } from "./_helpers"
|
import { getRepoInfo } from "./_helpers"
|
||||||
import pkg from "../package.json"
|
import pkg from "../package.json"
|
||||||
const nodeModules = fs.readdirSync("node_modules").filter(function(x) {
|
|
||||||
return x !== ".bin"
|
|
||||||
})
|
|
||||||
|
|
||||||
const projectBasePath = path.join(__dirname, "../")
|
const projectBasePath = path.join(__dirname, "../")
|
||||||
|
|
||||||
@@ -30,7 +27,7 @@ const baseRules = [
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ test: /\.(txt|yaml)$/,
|
{ test: /\.(txt|yaml)$/,
|
||||||
type: "asset/source",
|
type: "asset/source",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: /\.(png|jpg|jpeg|gif|svg)$/,
|
test: /\.(png|jpg|jpeg|gif|svg)$/,
|
||||||
@@ -93,24 +90,12 @@ export default function buildConfig(
|
|||||||
|
|
||||||
externals: includeDependencies
|
externals: includeDependencies
|
||||||
? {
|
? {
|
||||||
// json-react-schema/deeper depends on buffertools, which fails.
|
esprima: "esprima",
|
||||||
buffertools: true,
|
|
||||||
esprima: true,
|
|
||||||
}
|
}
|
||||||
: (context, request, cb) => {
|
: [nodeExternals({
|
||||||
// webpack injects some stuff into the resulting file,
|
importType: (moduleName) => {
|
||||||
// these libs need to be pulled in to keep that working.
|
return `commonjs ${moduleName}`
|
||||||
var exceptionsForWebpack = ["ieee754", "base64-js"]
|
}})],
|
||||||
if (
|
|
||||||
nodeModules.indexOf(request) !== -1 ||
|
|
||||||
exceptionsForWebpack.indexOf(request) !== -1
|
|
||||||
) {
|
|
||||||
cb(null, "commonjs " + request)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cb()
|
|
||||||
},
|
|
||||||
|
|
||||||
resolve: {
|
resolve: {
|
||||||
modules: [path.join(projectBasePath, "./src"), "node_modules"],
|
modules: [path.join(projectBasePath, "./src"), "node_modules"],
|
||||||
extensions: [".web.js", ".js", ".jsx", ".json", ".less"],
|
extensions: [".web.js", ".js", ".jsx", ".json", ".less"],
|
||||||
|
|||||||
@@ -2,17 +2,17 @@
|
|||||||
* @prettier
|
* @prettier
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Dev Note:
|
/** Dev Note:
|
||||||
* StatsWriterPlugin is disabled by default; uncomment to enable
|
* StatsWriterPlugin is disabled by default; uncomment to enable
|
||||||
* when enabled, rebuilding the bundle will cause error for assetSizeLimit,
|
* when enabled, rebuilding the bundle will cause error for assetSizeLimit,
|
||||||
* which we want to keep out of CI/CD
|
* which we want to keep out of CI/CD
|
||||||
* post build, cli command: npx webpack-bundle-analyzer <path>
|
* post build, cli command: npx webpack-bundle-analyzer <path>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import configBuilder from "./_config-builder"
|
import configBuilder from "./_config-builder"
|
||||||
import { DuplicatesPlugin } from "inspectpack/plugin"
|
import { DuplicatesPlugin } from "inspectpack/plugin"
|
||||||
import { WebpackBundleSizeAnalyzerPlugin } from "webpack-bundle-size-analyzer"
|
import { WebpackBundleSizeAnalyzerPlugin } from "webpack-bundle-size-analyzer"
|
||||||
// import path from "path"
|
import nodeExternals from "webpack-node-externals"
|
||||||
// import { StatsWriterPlugin } from "webpack-stats-plugin"
|
// import { StatsWriterPlugin } from "webpack-stats-plugin"
|
||||||
|
|
||||||
const result = configBuilder(
|
const result = configBuilder(
|
||||||
@@ -28,17 +28,32 @@ const result = configBuilder(
|
|||||||
"./src/index.js",
|
"./src/index.js",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
experiments: {
|
||||||
|
outputModule: true,
|
||||||
|
},
|
||||||
output: {
|
output: {
|
||||||
|
module: true,
|
||||||
|
libraryTarget: "module",
|
||||||
library: {
|
library: {
|
||||||
type: "commonjs2",
|
type: "module",
|
||||||
export: "default",
|
},
|
||||||
|
environment: {
|
||||||
|
module: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
externalsType: "module",
|
||||||
|
externals: [
|
||||||
|
{
|
||||||
|
esprima: "esprima",
|
||||||
|
},
|
||||||
|
nodeExternals({
|
||||||
|
importType: (moduleName) => {
|
||||||
|
return `module ${moduleName}`
|
||||||
|
}})
|
||||||
|
],
|
||||||
plugins: [
|
plugins: [
|
||||||
new DuplicatesPlugin({
|
new DuplicatesPlugin({
|
||||||
// emit compilation warning or error? (Default: `false`)
|
|
||||||
emitErrors: false,
|
emitErrors: false,
|
||||||
// display full duplicates information? (Default: `false`)
|
|
||||||
verbose: false,
|
verbose: false,
|
||||||
}),
|
}),
|
||||||
new WebpackBundleSizeAnalyzerPlugin("log.es-bundle-core-sizes.swagger-ui.txt"),
|
new WebpackBundleSizeAnalyzerPlugin("log.es-bundle-core-sizes.swagger-ui.txt"),
|
||||||
@@ -50,4 +65,5 @@ const result = configBuilder(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
export default result
|
export default result
|
||||||
|
|||||||
@@ -2,12 +2,12 @@
|
|||||||
* @prettier
|
* @prettier
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Dev Note:
|
/** Dev Note:
|
||||||
* StatsWriterPlugin is disabled by default; uncomment to enable
|
* StatsWriterPlugin is disabled by default; uncomment to enable
|
||||||
* when enabled, rebuilding the bundle will cause error for assetSizeLimit,
|
* when enabled, rebuilding the bundle will cause error for assetSizeLimit,
|
||||||
* which we want to keep out of CI/CD
|
* which we want to keep out of CI/CD
|
||||||
* post build, cli command: npx webpack-bundle-analyzer <path>
|
* post build, cli command: npx webpack-bundle-analyzer <path>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import configBuilder from "./_config-builder"
|
import configBuilder from "./_config-builder"
|
||||||
import { DuplicatesPlugin } from "inspectpack/plugin"
|
import { DuplicatesPlugin } from "inspectpack/plugin"
|
||||||
|
|||||||
Reference in New Issue
Block a user