Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

サーバーをesbuildに変更 #259

Merged
13 commits merged into from
Jan 19, 2022
Merged
3 changes: 3 additions & 0 deletions server/pretense/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
"cors": "^2.8.5",
"cross-env": "^7.0.3",
"dotenv": "^8.2.0",
"esbuild": "^0.12.24",
"esbuild-node-externals": "^1.3.0",
"eslint": "^7.24.0",
"eslint-config-prettier": "^8.2.0",
"eslint-config-standard": "^16.0.2",
Expand Down Expand Up @@ -90,6 +92,7 @@
"multer": "^1.4.2",
"mysql2": "^2.2.5",
"next": "^10.1.3",
"node-dev": "^7.0.0",
"node-fetch": "^2.6.1",
"nodemon-webpack-plugin": "^4.5.2",
"npm-run-all": "^4.1.5",
Expand Down
505 changes: 313 additions & 192 deletions server/pretense/yarn.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions server/templates/@orm=none/@server-dev-dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
esbuild
esbuild-node-externals
node-dev
3 changes: 3 additions & 0 deletions server/templates/@orm=prisma/@server-dev-dep
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
prisma
esbuild
esbuild-node-externals
node-dev
5 changes: 5 additions & 0 deletions server/templates/@orm=typeorm/@server-dev-dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
webpack
webpack-cli
webpack-node-externals
tsconfig-paths-webpack-plugin
nodemon-webpack-plugin
4 changes: 4 additions & 0 deletions server/templates/server/@orm=none/scripts/build.dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const { build } = require('esbuild')
const config = require('./config.dev.js')

build(config)
4 changes: 4 additions & 0 deletions server/templates/server/@orm=none/scripts/build.prod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const { build } = require('esbuild')
const config = require('./config.prod.js')

build(config).catch(() => process.exit(1))
12 changes: 12 additions & 0 deletions server/templates/server/@orm=none/scripts/config.common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { nodeExternalsPlugin } = require('esbuild-node-externals')
const path = require('path')

module.exports = {
entryPoints: [path.resolve(__dirname, '../entrypoints/index.ts')],
outdir: path.resolve(__dirname, '../'),
platform: 'node',
target: 'node12',
bundle: true,
plugins: [nodeExternalsPlugin()],
logLevel: 'info'
}
8 changes: 8 additions & 0 deletions server/templates/server/@orm=none/scripts/config.dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const config = require('./config.common')

module.exports = Object.assign(config, {
watch: true,
define: {
'process.env.NODE_ENV': `"development"`
}
})
8 changes: 8 additions & 0 deletions server/templates/server/@orm=none/scripts/config.prod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const config = require('./config.common')

module.exports = Object.assign(config, {
minify: true,
define: {
'process.env.NODE_ENV': `"production"`
}
})
4 changes: 4 additions & 0 deletions server/templates/server/@orm=prisma/scripts/build.dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const { build } = require('esbuild')
const config = require('./config.dev.js')

build(config)
4 changes: 4 additions & 0 deletions server/templates/server/@orm=prisma/scripts/build.prod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const { build } = require('esbuild')
const config = require('./config.prod.js')

build(config).catch(() => process.exit(1))
14 changes: 14 additions & 0 deletions server/templates/server/@orm=prisma/scripts/config.common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { nodeExternalsPlugin } = require('esbuild-node-externals')
const path = require('path')

module.exports = {
entryPoints: [path.resolve(__dirname, '../entrypoints/index.ts')<% if (serverless === 'lambda') { %>,
path.resolve(__dirname, '../entrypoints/lambda.ts'),
path.resolve(__dirname, '../entrypoints/lambda_migration.ts')<% } %>],
outdir: path.resolve(__dirname, '../'),
platform: 'node',
target: 'node12',
bundle: true,
plugins: [nodeExternalsPlugin()],
logLevel: 'info'
}
8 changes: 8 additions & 0 deletions server/templates/server/@orm=prisma/scripts/config.dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const config = require('./config.common')

module.exports = Object.assign(config, {
watch: true,
define: {
'process.env.NODE_ENV': `"development"`
}
})
8 changes: 8 additions & 0 deletions server/templates/server/@orm=prisma/scripts/config.prod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const config = require('./config.common')

module.exports = Object.assign(config, {
minify: true,
define: {
'process.env.NODE_ENV': `"production"`
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ const NodemonPlugin = require('nodemon-webpack-plugin')
/** @type import("webpack").Configuration */
module.exports = {
entry: {
index: './entrypoints/index.ts'<% if (serverless === 'lambda') { %>,
lambda: './entrypoints/lambda.ts',
lambda_migration: './entrypoints/lambda_migration.ts'<% } %>
},<% if (orm === 'typeorm') { %>
index: './entrypoints/index.ts'
},
// Suprress mangling since TypeORM relies on that.
optimization: {
minimize: false
},<% } %>
},
target: 'node',
node: {
__dirname: false
Expand Down
7 changes: 1 addition & 6 deletions server/templates/server/@server-dev-dep
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
cross-env
nodemon-webpack-plugin
npm-run-all
ts-loader
ts-node
tsconfig-paths-webpack-plugin
typescript
webpack
webpack-cli
webpack-node-externals
@types/jest
@types/jest
4 changes: 2 additions & 2 deletions server/templates/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"private": true,
"scripts": {
"dev": "<% if (orm === 'prisma') { %>npm run migrate:dev && <% } %>run-p dev:*",
"dev:server": "webpack --watch --mode=development",
"dev:server": "<% if (orm === 'typeorm') { %>webpack --watch --mode=development<% } else { %>node ./scripts/build.dev.js & node-dev index.js<% } %>",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long living 系は node-dev --respawn と指定しないと、 index.ts をいじって、一瞬、すぐ終わる形になったときに、再起動しなくなる。あったほうがよいかも?

"dev:frourio": "frourio<% if (server === 'express') { %>-express<% } %> --watch<% if (orm === 'prisma') { %>",
"dev:prisma": "prisma generate --watch<% } else if (orm === 'typeorm') { %>",
"dev:typeormer": "typeormer --watch<% } %>",
"prebuild": "npm run generate",
"build": "webpack --mode=production",
"build": "<% if (orm === 'typeorm') { %>webpack --mode=production<% } else { %>node ./scripts/build.prod.js<% } %>",
"generate": "run-p generate:*",
"generate:frourio": "frourio<% if (server === 'express') { %>-express<% } %><% if (orm === 'prisma') { %>",
"generate:prisma": "prisma generate<% } else if (orm === 'typeorm') { %>",
Expand Down