feat(build): webpack@5 and webpack-dev-server@4 (#7826)
SwaggerUI is now built using `webpack@5`, with dev support for `webpack-dev-server@4` - ES Module output bundle path now points to `swagger-ui-es-bundle-core`, which does not include dependencies - No change to CommonJS output bundle or path - Now uses Asset Modules, which replaces `file-loader`, `raw-loader`, and `url-loader` - Removed unused rules/loaders for `.woff | .woff2 | .ttf | .eot` fonts and html - Node polyfills are no longer bundled with `webpack@5`, and must be loaded separately and/or use `resolve.fallback`. As an example, SwaggerUI loads `process`, `buffer`, and `stream-browserify` as `devDependencies` in order to build development and production bundles. SwaggerUI-React - Now imports `swagger-ui-es-bundle-core`, and similarly outputs `swagger-ui-es-bundle-core` to its `dist` directory Dev notes: - Order of execution matters for the production npm build scripts. `build-stylesheets` needs to get built first, then cleanup of any empty artifacts, before building the various production bundles - `Dev-helpers` now relies on `HTMLWebpackPlugin` to inject css and bundle files
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
*/
|
||||
|
||||
import path from "path"
|
||||
import os from "os"
|
||||
import fs from "fs"
|
||||
import deepExtend from "deep-extend"
|
||||
import webpack from "webpack"
|
||||
@@ -30,26 +29,13 @@ const baseRules = [
|
||||
cacheDirectory: true,
|
||||
},
|
||||
},
|
||||
{ test: /\.(txt|yaml)$/, loader: "raw-loader" },
|
||||
{ test: /\.(txt|yaml)$/,
|
||||
type: "asset/source",
|
||||
},
|
||||
{
|
||||
test: /\.(png|jpg|jpeg|gif|svg)$/,
|
||||
use: [
|
||||
{
|
||||
loader: "url-loader",
|
||||
options: {
|
||||
esModule: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
type: "asset/inline",
|
||||
},
|
||||
{
|
||||
test: /\.(woff|woff2)$/,
|
||||
loader: "url-loader?",
|
||||
options: {
|
||||
limit: 10000,
|
||||
},
|
||||
},
|
||||
{ test: /\.(ttf|eot)$/, loader: "file-loader" },
|
||||
]
|
||||
|
||||
export default function buildConfig(
|
||||
@@ -72,6 +58,10 @@ export default function buildConfig(
|
||||
BUILD_TIME: new Date().toUTCString(),
|
||||
}),
|
||||
}),
|
||||
new webpack.ProvidePlugin({
|
||||
process: "process/browser",
|
||||
Buffer: ["buffer", "Buffer"],
|
||||
}),
|
||||
]
|
||||
|
||||
const completeConfig = deepExtend(
|
||||
@@ -86,16 +76,16 @@ export default function buildConfig(
|
||||
publicPath: "/dist",
|
||||
filename: "[name].js",
|
||||
chunkFilename: "[name].js",
|
||||
libraryTarget: "umd",
|
||||
libraryExport: "default", // TODO: enable
|
||||
globalObject: "this",
|
||||
library: {
|
||||
// when esm, library.name should be unset, so do not define here
|
||||
// when esm, library.export should be unset, so do not define here
|
||||
type: "umd",
|
||||
}
|
||||
},
|
||||
|
||||
target: "web",
|
||||
|
||||
node: {
|
||||
// yaml-js has a reference to `fs`, this is a workaround
|
||||
fs: "empty",
|
||||
},
|
||||
|
||||
module: {
|
||||
rules: baseRules,
|
||||
@@ -132,6 +122,11 @@ export default function buildConfig(
|
||||
"lodash": path.resolve(__dirname, "..", "node_modules/lodash"),
|
||||
"isarray": path.resolve(__dirname, "..", "node_modules/stream-browserify/node_modules/isarray"),
|
||||
"react-is": path.resolve(__dirname, "..", "node_modules/react-redux/node_modules/react-is"),
|
||||
"safe-buffer": path.resolve(__dirname, "..", "node_modules/string_decoder/node_modules/safe-buffer"),
|
||||
},
|
||||
fallback: {
|
||||
fs: false,
|
||||
stream: require.resolve("stream-browserify"),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -139,8 +134,8 @@ export default function buildConfig(
|
||||
// Otherwise, provide heavy souremaps suitable for development
|
||||
devtool: sourcemaps
|
||||
? minimize
|
||||
? "nosource-source-map"
|
||||
: "module-source-map"
|
||||
? "nosources-source-map"
|
||||
: "cheap-module-source-map"
|
||||
: false,
|
||||
|
||||
performance: {
|
||||
@@ -154,8 +149,6 @@ export default function buildConfig(
|
||||
minimizer: [
|
||||
compiler =>
|
||||
new TerserPlugin({
|
||||
cache: true,
|
||||
sourceMap: sourcemaps,
|
||||
terserOptions: {
|
||||
mangle: !!mangle,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user