mirror of
https://github.com/aleleba/create-node-ts-graphql-server.git
synced 2025-01-09 21:46:48 -06:00
PR-934611: making some changes to webpack and updating packages.
This commit is contained in:
parent
5262aac33c
commit
af983a8032
@ -1,5 +1,5 @@
|
|||||||
#ENVIRONMENT Defauld production
|
#ENVIRONMENT Defauld production
|
||||||
ENVIRONMENT=
|
ENV=
|
||||||
#WHITELIST URLS Default to http://localhost
|
#WHITELIST URLS Default to http://localhost
|
||||||
WHITELIST_URLS=
|
WHITELIST_URLS=
|
||||||
#GRAPHIQL Default to "false"
|
#GRAPHIQL Default to "false"
|
||||||
|
@ -4,8 +4,8 @@ This project aims to have a starter kit for creating a new Node with typescript,
|
|||||||
|
|
||||||
Tech(Library or Framework) | Version |
|
Tech(Library or Framework) | Version |
|
||||||
--- | --- |
|
--- | --- |
|
||||||
Jest (Testing) | 28.1.3
|
Jest (Testing) | 29.0.1
|
||||||
Typescript | 4.7.4
|
Typescript | 4.8.2
|
||||||
GraphQL | 16.6.0
|
GraphQL | 16.6.0
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
@ -3,11 +3,17 @@ import * as dotenv from 'dotenv';
|
|||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
export const config = {
|
export const config = {
|
||||||
env: process.env.ENVIRONMENT ? process.env.ENVIRONMENT : 'production',
|
ENV: process.env.ENV,
|
||||||
graphiQL: process.env.GRAPHIQL === 'true' ? true : false,
|
GRAPHIQL: process.env.GRAPHIQL === 'true' ? true : false,
|
||||||
playgroundGraphQL: process.env.PLAYGROUND_GRAPHQL === 'true' ? true : false,
|
PLAYGROUND_GRAPHQL: process.env.PLAYGROUND_GRAPHQL === 'true' ? true : false,
|
||||||
whiteList: process.env.WHITELIST_URLS ? process.env.WHITELIST_URLS.split(',') : [
|
WHITELIST_URLS: process.env.WHITELIST_URLS && process.env.WHITELIST_URLS.split(','),
|
||||||
'http://localhost'
|
PORT: process.env.PORT,
|
||||||
],
|
|
||||||
port: process.env.PORT || 4000,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const deFaultValues = {
|
||||||
|
ENV: 'production',
|
||||||
|
GRAPHIQL: 'false',
|
||||||
|
PLAYGROUND_GRAPHQL: 'false',
|
||||||
|
WHITELIST_URLS: 'http://localhost',
|
||||||
|
PORT: 4000,
|
||||||
|
}
|
4918
package-lock.json
generated
4918
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
20
package.json
20
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@aleleba/create-node-ts-graphql-server",
|
"name": "@aleleba/create-node-ts-graphql-server",
|
||||||
"version": "1.1.7",
|
"version": "1.2.0",
|
||||||
"description": "Node with Typescript and GraphQL Server",
|
"description": "Node with Typescript and GraphQL Server",
|
||||||
"bin": "./bin/cli.js",
|
"bin": "./bin/cli.js",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
@ -32,7 +32,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/aleleba/node-ts-graphql-server#readme",
|
"homepage": "https://github.com/aleleba/node-ts-graphql-server#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@graphql-tools/schema": "^9.0.1",
|
"@graphql-tools/schema": "^9.0.2",
|
||||||
"body-parser": "^1.20.0",
|
"body-parser": "^1.20.0",
|
||||||
"cookie-parser": "^1.4.6",
|
"cookie-parser": "^1.4.6",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
@ -42,7 +42,7 @@
|
|||||||
"graphql": "^16.6.0",
|
"graphql": "^16.6.0",
|
||||||
"graphql-playground-middleware-express": "^1.7.23",
|
"graphql-playground-middleware-express": "^1.7.23",
|
||||||
"graphql-subscriptions": "^2.0.0",
|
"graphql-subscriptions": "^2.0.0",
|
||||||
"graphql-tools": "^8.3.3",
|
"graphql-tools": "^8.3.4",
|
||||||
"graphql-ws": "^5.10.1",
|
"graphql-ws": "^5.10.1",
|
||||||
"web-push": "^3.5.0",
|
"web-push": "^3.5.0",
|
||||||
"ws": "^8.8.1"
|
"ws": "^8.8.1"
|
||||||
@ -52,23 +52,23 @@
|
|||||||
"@babel/preset-env": "^7.18.10",
|
"@babel/preset-env": "^7.18.10",
|
||||||
"@babel/preset-typescript": "^7.18.6",
|
"@babel/preset-typescript": "^7.18.6",
|
||||||
"@babel/register": "^7.18.9",
|
"@babel/register": "^7.18.9",
|
||||||
"@types/jest": "^28.1.7",
|
"@types/jest": "^29.0.0",
|
||||||
"@types/node": "^18.7.11",
|
"@types/node": "^18.7.14",
|
||||||
"@types/webpack": "^5.28.0",
|
"@types/webpack": "^5.28.0",
|
||||||
"@types/webpack-node-externals": "^2.5.3",
|
"@types/webpack-node-externals": "^2.5.3",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.34.0",
|
"@typescript-eslint/eslint-plugin": "^5.36.1",
|
||||||
"@typescript-eslint/parser": "^5.34.0",
|
"@typescript-eslint/parser": "^5.36.1",
|
||||||
"babel-loader": "^8.2.5",
|
"babel-loader": "^8.2.5",
|
||||||
"clean-webpack-plugin": "^4.0.0",
|
"clean-webpack-plugin": "^4.0.0",
|
||||||
"compression-webpack-plugin": "^10.0.0",
|
"compression-webpack-plugin": "^10.0.0",
|
||||||
"eslint": "^8.22.0",
|
"eslint": "^8.23.0",
|
||||||
"eslint-webpack-plugin": "^3.2.0",
|
"eslint-webpack-plugin": "^3.2.0",
|
||||||
"jest": "^28.1.3",
|
"jest": "^29.0.1",
|
||||||
"nodemon": "^2.0.19",
|
"nodemon": "^2.0.19",
|
||||||
"supertest": "^6.2.4",
|
"supertest": "^6.2.4",
|
||||||
"ts-jest": "^28.0.8",
|
"ts-jest": "^28.0.8",
|
||||||
"ts-loader": "^9.3.1",
|
"ts-loader": "^9.3.1",
|
||||||
"typescript": "^4.7.4",
|
"typescript": "^4.8.2",
|
||||||
"webpack": "^5.74.0",
|
"webpack": "^5.74.0",
|
||||||
"webpack-cli": "^4.10.0",
|
"webpack-cli": "^4.10.0",
|
||||||
"webpack-manifest-plugin": "^5.0.0",
|
"webpack-manifest-plugin": "^5.0.0",
|
||||||
|
@ -11,7 +11,7 @@ server.use(
|
|||||||
graphqlHTTP( (req, res) => {
|
graphqlHTTP( (req, res) => {
|
||||||
return {
|
return {
|
||||||
schema,
|
schema,
|
||||||
graphiql: config.graphiQL,
|
graphiql: config.GRAPHIQL,
|
||||||
context: { req, res }
|
context: { req, res }
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
|
@ -13,7 +13,7 @@ import { config } from '../config';
|
|||||||
import apiRouter from './routes';
|
import apiRouter from './routes';
|
||||||
|
|
||||||
const app = express(), //creating app
|
const app = express(), //creating app
|
||||||
whitelist = config.whiteList,
|
whitelist = config.WHITELIST_URLS,
|
||||||
corsOptions = {
|
corsOptions = {
|
||||||
origin: function (origin, callback) {
|
origin: function (origin, callback) {
|
||||||
if (whitelist.indexOf(origin) !== -1 || !origin) {
|
if (whitelist.indexOf(origin) !== -1 || !origin) {
|
||||||
@ -34,14 +34,14 @@ app
|
|||||||
.use(apiRouter)//Routes de App
|
.use(apiRouter)//Routes de App
|
||||||
.use('/graphql', GraphQLserver);//Server of Graphql
|
.use('/graphql', GraphQLserver);//Server of Graphql
|
||||||
|
|
||||||
if(config.playgroundGraphQL === true){
|
if(config.PLAYGROUND_GRAPHQL === true){
|
||||||
app.get('/playground', expressPlayground({ endpoint: '/graphql' }));
|
app.get('/playground', expressPlayground({ endpoint: '/graphql' }));
|
||||||
}
|
}
|
||||||
|
|
||||||
// DO NOT DO app.listen() unless we're testing this directly
|
// DO NOT DO app.listen() unless we're testing this directly
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
|
|
||||||
const server = app.listen(config.port, () => {
|
const server = app.listen(config.PORT, () => {
|
||||||
// create and use the websocket server
|
// create and use the websocket server
|
||||||
const wsServer = new ws.Server({
|
const wsServer = new ws.Server({
|
||||||
server,
|
server,
|
||||||
@ -74,7 +74,7 @@ if (require.main === module) {
|
|||||||
},
|
},
|
||||||
}, wsServer);
|
}, wsServer);
|
||||||
|
|
||||||
console.log(`Starting Express on port ${config.port} and iniciating server of web sockets`);
|
console.log(`Starting Express on port ${config.PORT} and iniciating server of web sockets`);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import * as dotenv from 'dotenv';
|
|
||||||
import webpack from 'webpack';
|
import webpack from 'webpack';
|
||||||
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
|
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
|
||||||
import ESLintPlugin from 'eslint-webpack-plugin';
|
import ESLintPlugin from 'eslint-webpack-plugin';
|
||||||
import nodeExternals from 'webpack-node-externals';
|
import nodeExternals from 'webpack-node-externals';
|
||||||
import WebpackShellPluginNext from 'webpack-shell-plugin-next';
|
import WebpackShellPluginNext from 'webpack-shell-plugin-next';
|
||||||
|
import { deFaultValues } from './config';
|
||||||
const dotEnvToParse = dotenv.config();
|
|
||||||
|
|
||||||
const ROOT_DIR = path.resolve(__dirname);
|
const ROOT_DIR = path.resolve(__dirname);
|
||||||
const resolvePath = (...args) => path.resolve(ROOT_DIR, ...args);
|
const resolvePath = (...args) => path.resolve(ROOT_DIR, ...args);
|
||||||
@ -50,12 +48,12 @@ const config = {
|
|||||||
plugins: [
|
plugins: [
|
||||||
new CleanWebpackPlugin(),
|
new CleanWebpackPlugin(),
|
||||||
new ESLintPlugin(),
|
new ESLintPlugin(),
|
||||||
new webpack.DefinePlugin({
|
new webpack.EnvironmentPlugin({
|
||||||
'process.env': JSON.stringify(dotEnvToParse.parsed),
|
...deFaultValues
|
||||||
}),
|
}),
|
||||||
new WebpackShellPluginNext({
|
new WebpackShellPluginNext({
|
||||||
onBuildEnd: {
|
onBuildEnd: {
|
||||||
scripts: ['npm run start:nodemon'],
|
scripts: ['nodemon build/index.js'],
|
||||||
blocking: false,
|
blocking: false,
|
||||||
parallel: true
|
parallel: true
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import * as dotenv from 'dotenv';
|
|
||||||
import webpack from 'webpack';
|
import webpack from 'webpack';
|
||||||
import TerserPlugin from 'terser-webpack-plugin';
|
import TerserPlugin from 'terser-webpack-plugin';
|
||||||
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
|
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
|
||||||
import ESLintPlugin from 'eslint-webpack-plugin';
|
import ESLintPlugin from 'eslint-webpack-plugin';
|
||||||
import nodeExternals from 'webpack-node-externals';
|
import nodeExternals from 'webpack-node-externals';
|
||||||
|
import { deFaultValues } from './config';
|
||||||
const dotEnvToParse = dotenv.config();
|
|
||||||
|
|
||||||
const ROOT_DIR = path.resolve(__dirname);
|
const ROOT_DIR = path.resolve(__dirname);
|
||||||
const resolvePath = (...args) => path.resolve(ROOT_DIR, ...args);
|
const resolvePath = (...args) => path.resolve(ROOT_DIR, ...args);
|
||||||
@ -49,8 +47,8 @@ const config = {
|
|||||||
plugins: [
|
plugins: [
|
||||||
new CleanWebpackPlugin(),
|
new CleanWebpackPlugin(),
|
||||||
new ESLintPlugin(),
|
new ESLintPlugin(),
|
||||||
new webpack.DefinePlugin({
|
new webpack.EnvironmentPlugin({
|
||||||
'process.env': JSON.stringify(dotEnvToParse.parsed),
|
...deFaultValues
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
optimization: {
|
optimization: {
|
||||||
|
Loading…
Reference in New Issue
Block a user