Added webpack for backend
This commit is contained in:
parent
1445f7341e
commit
adb21337bc
831
package-lock.json
generated
831
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
22
package.json
22
package.json
@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "nest-typescript-starter",
|
||||
"name": "fileserver",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"description": "Nest TypeScript starter repository",
|
||||
"description": "Crackhead fileserver",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"prebuild": "rimraf dist",
|
||||
@ -10,14 +10,14 @@
|
||||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
||||
"start": "nest start",
|
||||
"start:dev": "nest start --watch",
|
||||
"start:debug": "nest start --debug --watch",
|
||||
"start:prod": "node dist/main",
|
||||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
||||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\"",
|
||||
"lint-fix": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
||||
"test": "jest",
|
||||
"test:watch": "jest --watch",
|
||||
"test:cov": "jest --coverage",
|
||||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json",
|
||||
"webpack": "webpack --config webpack.config.ts",
|
||||
"genapi": "ts-node tools/apigen.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
@ -30,14 +30,12 @@
|
||||
"@nestjs/platform-fastify": "^9.0.8",
|
||||
"@nestjs/serve-static": "^3.0.0",
|
||||
"@nestjs/typeorm": "^9.0.0",
|
||||
"@typescript-eslint/typescript-estree": "^5.33.0",
|
||||
"argon2": "^0.28.7",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"passport": "^0.6.0",
|
||||
"passport-jwt": "^4.0.0",
|
||||
"passport-local": "^1.0.0",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"rxjs": "^7.5.6",
|
||||
"sqlite3": "^5.0.11",
|
||||
"typeorm": "^0.3.7"
|
||||
@ -53,20 +51,28 @@
|
||||
"@types/passport-jwt": "^3.0.6",
|
||||
"@types/passport-local": "^1.0.34",
|
||||
"@types/supertest": "^2.0.12",
|
||||
"@types/webpack": "^5.28.0",
|
||||
"@types/webpack-node-externals": "^2.5.3",
|
||||
"@typescript-eslint/eslint-plugin": "^5.33.0",
|
||||
"@typescript-eslint/parser": "^5.33.0",
|
||||
"@typescript-eslint/typescript-estree": "^5.33.0",
|
||||
"copy-webpack-plugin": "^11.0.0",
|
||||
"eslint": "^8.21.0",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"jest": "^28.1.3",
|
||||
"prettier": "^2.7.1",
|
||||
"rimraf": "^3.0.2",
|
||||
"source-map-support": "^0.5.21",
|
||||
"supertest": "^6.2.4",
|
||||
"ts-jest": "^28.0.7",
|
||||
"ts-loader": "^9.3.1",
|
||||
"ts-node": "^10.9.1",
|
||||
"tsconfig-paths": "^4.1.0",
|
||||
"typescript": "^4.7.4"
|
||||
"typescript": "^4.7.4",
|
||||
"webpack": "^5.74.0",
|
||||
"webpack-cli": "^4.10.0",
|
||||
"webpack-node-externals": "^3.0.0"
|
||||
},
|
||||
"jest": {
|
||||
"moduleFileExtensions": [
|
||||
|
@ -7,6 +7,8 @@ import AuthModule from './modules/auth';
|
||||
import { ServeStaticModule } from '@nestjs/serve-static';
|
||||
import { join } from 'path';
|
||||
|
||||
declare const PROD: boolean | undefined;
|
||||
|
||||
@Controller('test')
|
||||
class TestController {
|
||||
@Role(UserRole.USER)
|
||||
@ -31,7 +33,10 @@ class TestController {
|
||||
entities: [User, INode, JWTToken]
|
||||
}),
|
||||
ServeStaticModule.forRoot({
|
||||
rootPath: join(__dirname, '..', '..', 'frontend', 'dist'),
|
||||
rootPath:
|
||||
typeof PROD !== 'undefined' && PROD
|
||||
? join(__dirname, 'frontend')
|
||||
: join(__dirname, '..', '..', 'frontend', 'dist'),
|
||||
exclude: ['/api*']
|
||||
}),
|
||||
FileSystemModule,
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"declaration": false,
|
||||
"removeComments": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
|
55
webpack.config.ts
Normal file
55
webpack.config.ts
Normal file
@ -0,0 +1,55 @@
|
||||
import { DefinePlugin } from 'webpack';
|
||||
import * as nodeExternals from 'webpack-node-externals';
|
||||
import * as copyPlugin from 'copy-webpack-plugin';
|
||||
import { resolve } from 'path';
|
||||
|
||||
function transform_package(input: Buffer): string {
|
||||
const pkg = JSON.parse(input.toString());
|
||||
delete pkg['devDependencies'];
|
||||
delete pkg['jest'];
|
||||
pkg['scripts'] = {
|
||||
start: 'node server.js'
|
||||
};
|
||||
return JSON.stringify(pkg);
|
||||
}
|
||||
|
||||
export default {
|
||||
entry: './src/main.ts',
|
||||
plugins: [
|
||||
new DefinePlugin({
|
||||
PROD: JSON.stringify(true)
|
||||
}),
|
||||
new copyPlugin({
|
||||
patterns: [
|
||||
{
|
||||
from: resolve(__dirname, 'package.json'),
|
||||
to: resolve(__dirname, 'dist', 'package.json'),
|
||||
transform: transform_package
|
||||
},
|
||||
{
|
||||
from: resolve(__dirname, 'package-lock.json'),
|
||||
to: resolve(__dirname, 'dist', 'package-lock.json')
|
||||
}
|
||||
]
|
||||
})
|
||||
],
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.ts?$/,
|
||||
use: 'ts-loader'
|
||||
}
|
||||
]
|
||||
},
|
||||
externalsPresets: { node: true },
|
||||
mode: 'production',
|
||||
devtool: 'inline-source-map',
|
||||
resolve: {
|
||||
extensions: ['.ts', '.js']
|
||||
},
|
||||
output: {
|
||||
filename: 'server.js',
|
||||
path: resolve(__dirname, 'dist')
|
||||
},
|
||||
externals: [nodeExternals()]
|
||||
};
|
Loading…
Reference in New Issue
Block a user