Skip to content

Commit

Permalink
feat: add server schema build & export (#1072)
Browse files Browse the repository at this point in the history
* feat: add server schema build & export

* chore: add comment why bundle needed
  • Loading branch information
martyanovandrey authored Nov 12, 2024
1 parent eb86b60 commit d7e1b26
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ node_modules
/styles/**/*.css
/coverage
/widget
/schema

*.tgz
.env
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
53 changes: 53 additions & 0 deletions schema.webpack.js
Original file line number Diff line number Diff line change
@@ -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,
},
},
}),
],
},
};

0 comments on commit d7e1b26

Please sign in to comment.