Skip to content

Commit d7e1b26

Browse files
feat: add server schema build & export (#1072)
* feat: add server schema build & export * chore: add comment why bundle needed
1 parent eb86b60 commit d7e1b26

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ node_modules
1414
/styles/**/*.css
1515
/coverage
1616
/widget
17+
/schema
1718

1819
*.tgz
1920
.env

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"import": "./server/index.js"
2525
},
2626
"./styles/*": "./styles/*",
27-
"./widget/*": "./widget/*"
27+
"./widget/*": "./widget/*",
28+
"./schema/*": "./schema/*"
2829
},
2930
"main": "./build/cjs/index.js",
3031
"module": "./build/esm/index.js",
@@ -72,7 +73,8 @@
7273
"build:client": "gulp",
7374
"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",
7475
"build:widget": "webpack --config widget.webpack.js",
75-
"build": "run-p build:client build:server build:widget",
76+
"build:schema": "webpack --config schema.webpack.js",
77+
"build": "run-p build:client build:server build:widget build:schema",
7678
"prepublishOnly": "npm run lint && npm run build",
7779
"prepare": "husky install",
7880
"test": "jest",

schema.webpack.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* eslint-env node */
2+
// Schema generation has client dependencies, to run it on the node we bundle it.
3+
const path = require('path');
4+
5+
const TerserPlugin = require('terser-webpack-plugin');
6+
7+
const SRC_PATH = path.resolve('src');
8+
const SCHEMA_SRC_PATH = path.resolve(SRC_PATH, 'schema');
9+
const SCHEMA_RESULT_PATH = path.resolve(__dirname, 'schema');
10+
const SCHEMA_BUNDLE_FILENAME = 'index.js';
11+
12+
module.exports = {
13+
entry: path.resolve(SCHEMA_SRC_PATH, 'index.ts'),
14+
output: {
15+
path: SCHEMA_RESULT_PATH,
16+
filename: SCHEMA_BUNDLE_FILENAME,
17+
library: 'library',
18+
libraryTarget: 'umd',
19+
},
20+
mode: 'production',
21+
target: 'node',
22+
module: {
23+
rules: [
24+
{
25+
test: /\.[jt]sx?$/,
26+
exclude: [/node_modules/],
27+
use: {
28+
loader: 'babel-loader',
29+
},
30+
},
31+
{
32+
test: /\.css$/,
33+
use: 'null-loader',
34+
},
35+
],
36+
},
37+
resolve: {
38+
extensions: ['.tsx', '.ts', '.js'],
39+
},
40+
optimization: {
41+
minimize: true,
42+
minimizer: [
43+
new TerserPlugin({
44+
extractComments: false,
45+
terserOptions: {
46+
format: {
47+
comments: false,
48+
},
49+
},
50+
}),
51+
],
52+
},
53+
};

0 commit comments

Comments
 (0)