From d7e1b266476aa5750cf608e9f62c738dd75f227c Mon Sep 17 00:00:00 2001 From: Martyanov Andrey <37772440+martyanovandrey@users.noreply.github.com> Date: Tue, 12 Nov 2024 18:23:13 +0500 Subject: [PATCH] feat: add server schema build & export (#1072) * feat: add server schema build & export * chore: add comment why bundle needed --- .gitignore | 1 + package.json | 6 ++++-- schema.webpack.js | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 schema.webpack.js diff --git a/.gitignore b/.gitignore index 2f0397a01..ada2d4bd1 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ node_modules /styles/**/*.css /coverage /widget +/schema *.tgz .env diff --git a/package.json b/package.json index ca9d2db5a..c56a41e38 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,8 @@ "import": "./server/index.js" }, "./styles/*": "./styles/*", - "./widget/*": "./widget/*" + "./widget/*": "./widget/*", + "./schema/*": "./schema/*" }, "main": "./build/cjs/index.js", "module": "./build/esm/index.js", @@ -72,7 +73,8 @@ "build:client": "gulp", "build:server": "rimraf server && tsc -p tsconfig.server.json && move-file server/server.js server/index.js && move-file server/server.d.ts server/index.d.ts", "build:widget": "webpack --config widget.webpack.js", - "build": "run-p build:client build:server build:widget", + "build:schema": "webpack --config schema.webpack.js", + "build": "run-p build:client build:server build:widget build:schema", "prepublishOnly": "npm run lint && npm run build", "prepare": "husky install", "test": "jest", diff --git a/schema.webpack.js b/schema.webpack.js new file mode 100644 index 000000000..394d01d68 --- /dev/null +++ b/schema.webpack.js @@ -0,0 +1,53 @@ +/* eslint-env node */ +// Schema generation has client dependencies, to run it on the node we bundle it. +const path = require('path'); + +const TerserPlugin = require('terser-webpack-plugin'); + +const SRC_PATH = path.resolve('src'); +const SCHEMA_SRC_PATH = path.resolve(SRC_PATH, 'schema'); +const SCHEMA_RESULT_PATH = path.resolve(__dirname, 'schema'); +const SCHEMA_BUNDLE_FILENAME = 'index.js'; + +module.exports = { + entry: path.resolve(SCHEMA_SRC_PATH, 'index.ts'), + output: { + path: SCHEMA_RESULT_PATH, + filename: SCHEMA_BUNDLE_FILENAME, + library: 'library', + libraryTarget: 'umd', + }, + mode: 'production', + target: 'node', + module: { + rules: [ + { + test: /\.[jt]sx?$/, + exclude: [/node_modules/], + use: { + loader: 'babel-loader', + }, + }, + { + test: /\.css$/, + use: 'null-loader', + }, + ], + }, + resolve: { + extensions: ['.tsx', '.ts', '.js'], + }, + optimization: { + minimize: true, + minimizer: [ + new TerserPlugin({ + extractComments: false, + terserOptions: { + format: { + comments: false, + }, + }, + }), + ], + }, +};