Added Swagger

This commit is contained in:
2020-06-10 08:25:21 +02:00
parent 5c6f37eaf7
commit af76cbca87
257 changed files with 48861 additions and 12 deletions
@@ -0,0 +1,31 @@
/**
* @prettier
*/
export default class RemoveSourcemapsLackingMatchingAssetsPlugin {
apply(compiler) {
// Specify the event hook to attach to
compiler.hooks.emit.tap(
"RemoveSourcemapsLackingMatchingAssetsPlugin",
compilation => {
const assetNames = Object.keys(compilation.assets)
const sourcemapAssetNames = assetNames.filter(str =>
str.endsWith(".map")
)
const sourcemapAssetsWithoutMatchingSourceAsset = sourcemapAssetNames.filter(
name => {
return assetNames.indexOf(name.slice(0, -4)) === -1
}
)
sourcemapAssetsWithoutMatchingSourceAsset.forEach(name => {
console.warn(
`RemoveSourcemapsLackingMatchingAssetsPlugin: blocking emission of "${name}"`
)
delete compilation.assets[name]
})
}
)
}
}
+211
View File
@@ -0,0 +1,211 @@
/**
* @prettier
*/
import path from "path"
import os from "os"
import fs from "fs"
import deepExtend from "deep-extend"
import webpack from "webpack"
import TerserPlugin from "terser-webpack-plugin"
import RemoveSourcemapsLackingMatchingAssetsPlugin from "./_RemoveSourcemapsLackingMatchingAssetsPlugin.babel.js"
import { getRepoInfo } from "./_helpers"
import pkg from "../package.json"
const nodeModules = fs.readdirSync("node_modules").filter(function(x) {
return x !== ".bin"
})
const projectBasePath = path.join(__dirname, "../")
const baseRules = [
{
test: /\.jsx?$/,
include: [
path.join(projectBasePath, "src"),
path.join(projectBasePath, "node_modules", "object-assign-deep"),
],
loader: "babel-loader",
options: {
retainLines: true,
cacheDirectory: true,
},
},
{ test: /\.(txt|yaml)$/, loader: "raw-loader" },
{ test: /\.(png|jpg|jpeg|gif|svg)$/, loader: "url-loader" },
{
test: /\.(woff|woff2)$/,
loader: "url-loader?",
options: {
limit: 10000,
},
},
{ test: /\.(ttf|eot)$/, loader: "file-loader" },
]
export default function buildConfig(
{
minimize = true,
mangle = true,
sourcemaps = true,
includeDependencies = true,
includeStyles = false,
emitWorkerAssets = false,
},
customConfig
) {
const gitInfo = getRepoInfo()
const plugins = [
new webpack.DefinePlugin({
"process.env.CI": process.env.CI || false,
buildInfo: JSON.stringify({
PACKAGE_VERSION: pkg.version,
GIT_COMMIT: gitInfo.hash,
GIT_DIRTY: gitInfo.dirty,
HOSTNAME: os.hostname(),
BUILD_TIME: new Date().toUTCString(),
}),
}),
new RemoveSourcemapsLackingMatchingAssetsPlugin(),
]
//// Workers
baseRules.push({
test: /\.worker\.js$/,
use: [
{
loader: "worker-loader",
options: {
inline: true,
name: "[name].js",
fallback: !!emitWorkerAssets,
},
},
"babel-loader",
],
})
//// Styles
baseRules.push({
test: [/\.less$/],
use: includeStyles
? [
"style-loader",
{
loader: "css-loader",
options: { sourceMap: true },
},
{
loader: "postcss-loader",
options: {
sourceMap: true,
plugins: loader => [
require("cssnano")(),
require("autoprefixer")(),
],
},
},
{
loader: "less-loader",
options: {
sourceMap: true,
},
},
]
: "null-loader",
})
const completeConfig = deepExtend(
{},
{
mode: "production",
entry: {},
output: {
path: path.join(projectBasePath, "dist"),
publicPath: "/dist",
filename: "[name].js",
chunkFilename: "[id].[chunkhash].js",
libraryTarget: "umd",
libraryExport: "default", // TODO: enable
},
target: "web",
node: {
// yaml-js has a reference to `fs`, this is a workaround
fs: "empty",
},
module: {
rules: baseRules,
},
externals: includeDependencies
? {
// json-react-schema/deeper depends on buffertools, which fails.
buffertools: true,
esprima: true,
}
: (context, request, cb) => {
// webpack injects some stuff into the resulting file,
// these libs need to be pulled in to keep that working.
var exceptionsForWebpack = ["ieee754", "base64-js"]
if (
nodeModules.indexOf(request) !== -1 ||
exceptionsForWebpack.indexOf(request) !== -1
) {
cb(null, "commonjs " + request)
return
}
cb()
},
resolve: {
extensions: [".js", ".jsx", "json"],
alias: {
react: path.resolve(projectBasePath, "node_modules", "react")
},
},
// If we're mangling, size is a concern -- so use trace-only sourcemaps
// Otherwise, provide heavy sourcemaps suitable for development
devtool: sourcemaps
? minimize
? "nosource-source-map"
: "module-source-map"
: false,
performance: {
hints: "error",
maxEntrypointSize: 1024000,
maxAssetSize: 1024000,
},
optimization: {
minimize: !!minimize,
minimizer: [
compiler =>
new TerserPlugin({
cache: true,
sourceMap: sourcemaps,
terserOptions: {
mangle: !!mangle,
},
}).apply(compiler),
],
},
},
customConfig
)
// deepExtend mangles Plugin instances, this doesn't
completeConfig.plugins = plugins.concat(customConfig.plugins || [])
return completeConfig
}
+17
View File
@@ -0,0 +1,17 @@
/**
* @prettier
*/
import { gitDescribeSync } from "git-describe"
export function getRepoInfo() {
try {
return gitDescribeSync(__dirname)
} catch (e) {
console.error(e)
return {
hash: "noGit",
dirty: false,
}
}
}
+37
View File
@@ -0,0 +1,37 @@
/**
* @prettier
*/
import configBuilder from "./_config-builder"
const result = configBuilder(
{
minimize: true,
mangle: true,
sourcemaps: true,
includeDependencies: true,
includeStyles: true,
emitWorkerAssets: true,
},
{
entry: {
"swagger-editor-bundle": [
"./src/styles/main.less",
"./src/polyfills.js",
"./src/index.js",
],
},
output: {
library: "SwaggerEditorBundle",
},
performance: {
hints: "error",
maxEntrypointSize: 1024000 * 3.25, // MB
maxAssetSize: 1024000 * 3.25, // MB
},
}
)
export default result
+33
View File
@@ -0,0 +1,33 @@
/**
* @prettier
*/
import configBuilder from "./_config-builder"
const result = configBuilder(
{
minimize: true,
mangle: true,
sourcemaps: true,
includeDependencies: false,
includeStyles: false,
emitWorkerAssets: false,
},
{
entry: {
"swagger-editor": ["./src/polyfills.js", "./src/index.js"],
},
output: {
library: "SwaggerEditorBundle",
},
performance: {
hints: "error",
maxEntrypointSize: 1024000, // 1MB
maxAssetSize: 1024000, // 1MB
},
}
)
export default result
+69
View File
@@ -0,0 +1,69 @@
/**
* @prettier
*/
import path from "path"
import { HotModuleReplacementPlugin } from "webpack"
import configBuilder from "./_config-builder"
import styleConfig from "./stylesheets.babel"
const devConfig = configBuilder(
{
minimize: false,
mangle: false,
sourcemaps: true,
includeDependencies: true,
includeStyles: true,
emitWorkerAssets: false,
},
{
mode: "development",
entry: {
"swagger-editor-bundle": [
"./src/polyfills.js", // TODO: remove?
"./src/index.js",
],
"swagger-editor-standalone-preset": [
"./src/polyfills", // TODO: remove?
"./src/standalone/index.js",
],
"swagger-editor": "./src/styles/main.less",
},
performance: {
hints: false,
},
output: {
library: "[name]",
filename: "[name].js",
chunkFilename: "[id].js",
globalObject: "this", // HMR breaks WebWorker without this
},
devServer: {
port: 3200,
publicPath: "/",
disableHostCheck: true, // for development within VMs
stats: {
colors: true,
},
hot: true,
contentBase: path.join(__dirname, "../", "dev-helpers"),
host: "0.0.0.0",
},
plugins: [new HotModuleReplacementPlugin()],
}
)
// mix in the style config's plugins and loader rules
devConfig.plugins = [...devConfig.plugins, ...styleConfig.plugins]
devConfig.module.rules = [
...devConfig.module.rules,
...styleConfig.module.rules,
]
export default devConfig
+30
View File
@@ -0,0 +1,30 @@
/**
* @prettier
*/
import configBuilder from "./_config-builder"
const result = configBuilder(
{
minimize: true,
mangle: true,
sourcemaps: true,
includeDependencies: true,
includeStyles: false,
emitWorkerAssets: false,
},
{
entry: {
"swagger-editor-standalone-preset": [
"./src/polyfills.js",
"./src/standalone/index.js",
],
},
output: {
library: "SwaggerEditorStandalonePreset",
},
}
)
export default result
+81
View File
@@ -0,0 +1,81 @@
/**
* @prettier
*/
// 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"
import IgnoreAssetsPlugin from "ignore-assets-webpack-plugin"
export default {
mode: "production",
entry: {
"swagger-editor": ["./src/styles/main.less"],
},
module: {
rules: [
{
test: [/\.less$/],
use: [
{
loader: MiniCssExtractPlugin.loader,
},
{
loader: "css-loader",
options: { sourceMap: true },
},
{
loader: "postcss-loader",
options: {
sourceMap: true,
plugins: loader => [
require("cssnano")(),
require("autoprefixer")(),
],
},
},
{
loader: "less-loader",
options: {
sourceMap: true,
},
},
],
},
{
test: [/\.css$/],
use: [
{
loader: MiniCssExtractPlugin.loader,
},
{
loader: "css-loader",
options: { sourceMap: true },
},
],
},
],
},
plugins: [
new MiniCssExtractPlugin({
filename: "[name].css",
}),
new IgnoreAssetsPlugin({
// This is a hack to avoid a Webpack/MiniCssExtractPlugin bug, for more
// info see https://github.com/webpack-contrib/mini-css-extract-plugin/issues/151
ignore: ["swagger-editor.js", "swagger-editor.js.map"],
}),
],
devtool: "source-map",
output: {
path: path.join(__dirname, "../", "dist"),
publicPath: "/dist",
},
}
+39
View File
@@ -0,0 +1,39 @@
/**
* @prettier
*/
import configBuilder from "./_config-builder"
const result = configBuilder(
{
minimize: false,
mangle: false,
sourcemaps: false,
includeDependencies: true,
includeStyles: true,
emitWorkerAssets: false,
},
{
entry: {
"swagger-editor-bundle": [
"./src/styles/main.less",
"./src/polyfills.js",
"./src/index.js",
],
},
output: {
library: "SwaggerEditorBundle",
path: path.join(
__dirname,
require("../package.json").config.deps_check_dir
),
},
performance: {
hints: false,
},
}
)
export default result