Skip to content

Commit 6ab4441

Browse files
authored
Use webpack+ts-loader instead of babel (#82)
1 parent 0525a68 commit 6ab4441

File tree

7 files changed

+1955
-1006
lines changed

7 files changed

+1955
-1006
lines changed

.babelrc

Lines changed: 0 additions & 14 deletions
This file was deleted.

package.json

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"license": "MIT",
55
"scripts": {
66
"postinstall": "yarn run generate",
7-
"dev": "nodemon --watch 'src/**/*.*' --exec babel-node --extensions '.ts' src/index.ts",
7+
"dev": "cross-env TS_NODE_PROJECT=\"tsconfig.webpack-config.json\" NODE_ENV=development webpack --watch",
88
"start": "node lib",
99
"generate": "graphql-codegen",
10-
"build": "babel src --out-dir lib --extensions '.ts'",
10+
"build": "cross-env TS_NODE_PROJECT=\"tsconfig.webpack-config.json\" NODE_ENV=production webpack",
1111
"build-docker-image": "docker build -t pepakriz/gitlab-merger-bot:latest .",
1212
"build-bin": "pkg -t node10-alpine-x64 lib/index.js --output ./gitlab-merger-bot",
1313
"check": "yarn run check:cs && yarn run check:types && yarn run check:tests",
@@ -24,19 +24,11 @@
2424
"env-var": "^6.0.4",
2525
"express": "^4.17.1",
2626
"fast-deep-equal": "^3.1.1",
27-
"graphql-import": "^1.0.1",
2827
"node-fetch": "^2.3.0",
2928
"serve-static": "^1.14.1",
3029
"uuid": "^7.0.3"
3130
},
3231
"devDependencies": {
33-
"@babel/cli": "^7.8.4",
34-
"@babel/core": "^7.8.7",
35-
"@babel/node": "^7.8.7",
36-
"@babel/plugin-proposal-class-properties": "^7.8.3",
37-
"@babel/plugin-proposal-object-rest-spread": "^7.8.3",
38-
"@babel/preset-env": "^7.8.7",
39-
"@babel/preset-typescript": "^7.8.3",
4032
"@graphql-codegen/cli": "^1.13.2",
4133
"@graphql-codegen/core": "^1.13.2",
4234
"@graphql-codegen/typescript": "^1.13.2",
@@ -47,15 +39,24 @@
4739
"@types/node": "^13.7.7",
4840
"@types/node-fetch": "^2.5.5",
4941
"@types/uuid": "^7.0.2",
42+
"@types/webpack": "^4.41.10",
43+
"@types/webpack-node-externals": "^1.7.1",
44+
"cross-env": "^7.0.2",
5045
"husky": "^4.2.3",
5146
"jest": "^25.1.0",
5247
"nodemon": "^2.0.2",
48+
"nodemon-webpack-plugin": "^4.3.1",
5349
"pkg": "^4.4.4",
5450
"prettier": "^2.0.4",
5551
"pretty-quick": "^2.0.1",
5652
"ts-jest": "^25.2.1",
53+
"ts-loader": "^6.2.2",
5754
"ts-node": "^8.6.2",
58-
"typescript": "^3.8.3"
55+
"typescript": "^3.8.3",
56+
"webpack": "^4.42.1",
57+
"webpack-cli": "^3.3.11",
58+
"webpack-graphql-loader": "^1.0.2",
59+
"webpack-node-externals": "^1.7.2"
5960
},
6061
"jest": {
6162
"moduleFileExtensions": [

src/WebHookServer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ import { ApolloServer, gql } from 'apollo-server-express';
1010
import { PubSub } from 'apollo-server';
1111
import http from 'http';
1212
import { AppEvent } from './Types';
13-
import { importSchema } from 'graphql-import';
1413
import { Resolvers } from './generated/graphqlgen';
1514
import { Config } from './Config';
1615

16+
// @ts-ignore
17+
import typeDefs from '../schema.graphql';
18+
1719
interface MergeRequestAssignee {
1820
username: string;
1921
}
@@ -204,7 +206,6 @@ export class WebHookServer {
204206
},
205207
};
206208

207-
const typeDefs = importSchema(path.join(process.cwd(), 'schema.graphql'));
208209
const server = new ApolloServer({
209210
typeDefs,
210211
resolvers,

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
"*": ["node_modules/*", "src/types/*"]
1313
}
1414
},
15-
"include": ["src/**/*"]
15+
"include": ["src/**/*", "schema.graphql"]
1616
}

tsconfig.webpack-config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"target": "es2019",
5+
"esModuleInterop": true,
6+
"resolveJsonModule": true
7+
}
8+
}

webpack.config.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import path from 'path';
2+
3+
import webpack, { Configuration } from 'webpack';
4+
import nodeExternals from 'webpack-node-externals';
5+
import NodemonPlugin from 'nodemon-webpack-plugin';
6+
7+
const plugins = [new webpack.EnvironmentPlugin({ WEBPACK: true })];
8+
9+
if (process.env.NODE_ENV !== 'production') {
10+
plugins.push(new NodemonPlugin());
11+
}
12+
13+
const config: Configuration = {
14+
mode: process.env.NODE_ENV !== 'production' ? 'development' : 'development',
15+
entry: './src/index.ts',
16+
target: 'node',
17+
externals: [nodeExternals()],
18+
devtool: process.env.NODE_ENV !== 'production' ? 'cheap-module-eval-source-map' : 'source-map',
19+
module: {
20+
rules: [
21+
{
22+
test: /\.tsx?$/,
23+
use: 'ts-loader',
24+
exclude: /node_modules/,
25+
},
26+
{
27+
test: /\.mjs$/,
28+
include: /node_modules/,
29+
type: 'javascript/auto',
30+
},
31+
{
32+
test: /\.graphql?$/,
33+
use: [
34+
{
35+
loader: 'webpack-graphql-loader',
36+
options: {
37+
// validate: true,
38+
// schema: "./path/to/schema.json",
39+
// removeUnusedFragments: true
40+
// etc. See "Loader Options" below
41+
},
42+
},
43+
],
44+
},
45+
],
46+
},
47+
resolve: {
48+
extensions: ['.tsx', '.ts', '.mjs', '.js'],
49+
},
50+
output: {
51+
libraryTarget: 'commonjs',
52+
filename: 'index.js',
53+
path: path.resolve(__dirname, 'lib'),
54+
},
55+
plugins,
56+
};
57+
58+
module.exports = config;

0 commit comments

Comments
 (0)