chore: cli webpack
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"collection": "@nestjs/schematics",
|
||||
"sourceRoot": "src"
|
||||
}
|
||||
"sourceRoot": "src",
|
||||
"compilerOptions": {}
|
||||
}
|
||||
55
package.json
55
package.json
@@ -22,7 +22,7 @@
|
||||
"build": "nest build",
|
||||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
||||
"start": "cross-env NODE_ENV=development nest start -w",
|
||||
"start:dev": "nest start --watch",
|
||||
"start:dev": "nest build --webpack --webpackPath webpack-hmr.config.js --watch",
|
||||
"start:debug": "cross-env NODE_ENV=development nest start --debug --watch",
|
||||
"start:prod": "cross-env NODE_ENV=production node dist/main",
|
||||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
||||
@@ -37,25 +37,25 @@
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nestjs/common": "^8.0.4",
|
||||
"@nestjs/common": "^8.0.6",
|
||||
"@nestjs/config": "^1.0.1",
|
||||
"@nestjs/core": "^8.0.4",
|
||||
"@nestjs/passport": "^8.0.0",
|
||||
"@nestjs/platform-fastify": "^8.0.4",
|
||||
"@nestjs/swagger": "^5.0.8",
|
||||
"@typegoose/auto-increment": "^0.6.0",
|
||||
"@typegoose/typegoose": "8.0.0",
|
||||
"@nestjs/core": "^8.0.6",
|
||||
"@nestjs/passport": "^8.0.1",
|
||||
"@nestjs/platform-fastify": "^8.0.6",
|
||||
"@nestjs/swagger": "^5.0.9",
|
||||
"@typegoose/auto-increment": "^0.9.0",
|
||||
"@typegoose/typegoose": "8.1.1",
|
||||
"@types/bcrypt": "^5.0.0",
|
||||
"argv": "^0.0.2",
|
||||
"bcrypt": "^5.0.1",
|
||||
"chalk": "^4.1.1",
|
||||
"chalk": "^4.1.2",
|
||||
"class-transformer": "^0.4.0",
|
||||
"class-validator": "^0.13.1",
|
||||
"fastify-swagger": "^4.8.3",
|
||||
"fastify-swagger": "^4.8.4",
|
||||
"husky": "^7.0.1",
|
||||
"lint-staged": "^11.1.0",
|
||||
"lint-staged": "^11.1.2",
|
||||
"lodash": "^4.17.21",
|
||||
"mongoose": "^5.13.3",
|
||||
"mongoose": "^5.13.7",
|
||||
"mongoose-lean-virtuals": "^0.8.0",
|
||||
"nestjs-typegoose": "^7.1.38",
|
||||
"passport": "^0.4.1",
|
||||
@@ -63,32 +63,35 @@
|
||||
"passport-local": "^1.0.0",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"rxjs": "^7.2.0",
|
||||
"rxjs": "^7.3.0",
|
||||
"snakecase-keys": "^4.0.2",
|
||||
"zx": "^2.0.0"
|
||||
"zx": "^2.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nestjs/cli": "^8.0.2",
|
||||
"@nestjs/cli": "^8.1.1",
|
||||
"@nestjs/schematics": "^8.0.2",
|
||||
"@nestjs/testing": "^8.0.4",
|
||||
"@nestjs/testing": "^8.0.6",
|
||||
"@types/express": "^4.17.13",
|
||||
"@types/jest": "^26.0.24",
|
||||
"@types/lodash": "^4.14.171",
|
||||
"@types/node": "^16.4.0",
|
||||
"@types/jest": "^27.0.1",
|
||||
"@types/lodash": "^4.14.172",
|
||||
"@types/node": "^16.6.1",
|
||||
"@types/supertest": "^2.0.11",
|
||||
"@typescript-eslint/eslint-plugin": "4.28.4",
|
||||
"@typescript-eslint/parser": "4.28.4",
|
||||
"@typescript-eslint/eslint-plugin": "4.29.1",
|
||||
"@typescript-eslint/parser": "4.29.1",
|
||||
"cross-env": "^7.0.3",
|
||||
"eslint": "^7.31.0",
|
||||
"eslint": "^7.32.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-prettier": "^3.4.0",
|
||||
"jest": "27.0.6",
|
||||
"prettier": "^2.3.2",
|
||||
"supertest": "^6.1.4",
|
||||
"run-script-webpack-plugin": "^0.0.11",
|
||||
"supertest": "^6.1.5",
|
||||
"ts-jest": "^27.0.4",
|
||||
"ts-loader": "^9.2.3",
|
||||
"ts-node": "^10.1.0",
|
||||
"ts-loader": "^9.2.5",
|
||||
"ts-node": "^10.2.0",
|
||||
"tsconfig-paths": "^3.10.1",
|
||||
"typescript": "^4.3.5"
|
||||
"typescript": "^4.3.5",
|
||||
"webpack": "^5.50.0",
|
||||
"webpack-node-externals": "^3.0.0"
|
||||
}
|
||||
}
|
||||
825
pnpm-lock.yaml
generated
825
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -14,7 +14,9 @@ export const CROSS_DOMAIN = {
|
||||
}
|
||||
|
||||
export const MONGO_DB = {
|
||||
uri: `mongodb://127.0.0.1:${argv.dbport || '27017'}/mx-space`,
|
||||
uri: `mongodb://127.0.0.1:${argv.dbport || '27017'}/${
|
||||
process.env.TEST ? 'mx-space_unitest' : 'mx-space'
|
||||
}`,
|
||||
}
|
||||
|
||||
export const REDIS = {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Controller, Get } from '@nestjs/common'
|
||||
import PKG from '../package.json'
|
||||
// import { $ } from 'zx'
|
||||
import { execSync } from 'child_process'
|
||||
@Controller()
|
||||
export class AppController {
|
||||
@@ -8,7 +7,6 @@ export class AppController {
|
||||
async appInfo(): Promise<IAppInfo> {
|
||||
const cmd = `git log --pretty=oneline | head -n 1 | cut -d' ' -f1`
|
||||
const hash = execSync(cmd, { encoding: 'utf-8' }).split('\n')[0]
|
||||
// const hash = await $`git log --pretty=oneline | head -n 1 | cut -d' ' -f1`
|
||||
return {
|
||||
// hash: hash.stdout,
|
||||
name: PKG.name,
|
||||
|
||||
@@ -10,6 +10,7 @@ import { CROSS_DOMAIN } from './app.config'
|
||||
const PORT = 2333
|
||||
const APIVersion = 1
|
||||
const Origin = CROSS_DOMAIN.allowedOrigins
|
||||
declare const module: any
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create<NestFastifyApplication>(
|
||||
@@ -51,5 +52,10 @@ async function bootstrap() {
|
||||
|
||||
Logger.log('Server is up.')
|
||||
})
|
||||
|
||||
if (module.hot) {
|
||||
module.hot.accept()
|
||||
module.hot.dispose(() => app.close())
|
||||
}
|
||||
}
|
||||
bootstrap()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing'
|
||||
import { getFakeCategoryModel, getFakePostModel } from 'test/db-model.mock'
|
||||
import { DbModule } from '../helper/db.module'
|
||||
import { PostModule } from '../post/post.module'
|
||||
import { CategoryService } from './category.service'
|
||||
|
||||
@@ -8,8 +8,8 @@ describe('CategoryService', () => {
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [getFakePostModel(), getFakeCategoryModel(), CategoryService],
|
||||
imports: [PostModule],
|
||||
providers: [CategoryService],
|
||||
imports: [PostModule, DbModule],
|
||||
}).compile()
|
||||
|
||||
service = module.get<CategoryService>(CategoryService)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { forwardRef } from '@nestjs/common'
|
||||
import { Test, TestingModule } from '@nestjs/testing'
|
||||
import { getFakeCategoryModel, getFakePostModel } from 'test/db-model.mock'
|
||||
import { CategoryModule } from '../category/category.module'
|
||||
import { getFakeCategoryModel } from 'test/db-model.mock'
|
||||
import { CategoryService } from '../category/category.service'
|
||||
import { DbModule } from '../helper/db.module'
|
||||
import { PostService } from './post.service'
|
||||
|
||||
describe('PostService', () => {
|
||||
@@ -9,8 +9,8 @@ describe('PostService', () => {
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [getFakePostModel(), getFakeCategoryModel(), PostService],
|
||||
imports: [forwardRef(() => CategoryModule)],
|
||||
providers: [PostService, CategoryService, getFakeCategoryModel()],
|
||||
imports: [DbModule],
|
||||
}).compile()
|
||||
|
||||
service = module.get<PostService>(PostService)
|
||||
|
||||
22
webpack-hmr.config.js
Normal file
22
webpack-hmr.config.js
Normal file
@@ -0,0 +1,22 @@
|
||||
const nodeExternals = require('webpack-node-externals')
|
||||
const { RunScriptWebpackPlugin } = require('run-script-webpack-plugin')
|
||||
|
||||
module.exports = function (options, webpack) {
|
||||
return {
|
||||
...options,
|
||||
entry: ['webpack/hot/poll?100', options.entry],
|
||||
externals: [
|
||||
nodeExternals({
|
||||
allowlist: ['webpack/hot/poll?100'],
|
||||
}),
|
||||
],
|
||||
plugins: [
|
||||
...options.plugins,
|
||||
new webpack.HotModuleReplacementPlugin(),
|
||||
new webpack.WatchIgnorePlugin({
|
||||
paths: [/\.js$/, /\.d\.ts$/],
|
||||
}),
|
||||
new RunScriptWebpackPlugin({ name: options.output.filename }),
|
||||
],
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user