mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-29 11:02:28 +08:00
chore(nx/desktop): switch to webpack-based build
This commit is contained in:
parent
492e953517
commit
15fbe41312
22
apps/desktop-e2e/.spec.swcrc
Normal file
22
apps/desktop-e2e/.spec.swcrc
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"jsc": {
|
||||||
|
"target": "es2017",
|
||||||
|
"parser": {
|
||||||
|
"syntax": "typescript",
|
||||||
|
"decorators": true,
|
||||||
|
"dynamicImport": true
|
||||||
|
},
|
||||||
|
"transform": {
|
||||||
|
"decoratorMetadata": true,
|
||||||
|
"legacyDecorator": true
|
||||||
|
},
|
||||||
|
"keepClassNames": true,
|
||||||
|
"externalHelpers": true,
|
||||||
|
"loose": true
|
||||||
|
},
|
||||||
|
"module": {
|
||||||
|
"type": "es6"
|
||||||
|
},
|
||||||
|
"sourceMaps": true,
|
||||||
|
"exclude": []
|
||||||
|
}
|
5
apps/desktop-e2e/eslint.config.mjs
Normal file
5
apps/desktop-e2e/eslint.config.mjs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import baseConfig from "../../eslint.config.mjs";
|
||||||
|
|
||||||
|
export default [
|
||||||
|
...baseConfig
|
||||||
|
];
|
24
apps/desktop-e2e/jest.config.ts
Normal file
24
apps/desktop-e2e/jest.config.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
import { readFileSync } from 'fs';
|
||||||
|
|
||||||
|
// Reading the SWC compilation config for the spec files
|
||||||
|
const swcJestConfig = JSON.parse(
|
||||||
|
readFileSync(`${__dirname}/.spec.swcrc`, 'utf-8')
|
||||||
|
);
|
||||||
|
|
||||||
|
// Disable .swcrc look-up by SWC core because we're passing in swcJestConfig ourselves
|
||||||
|
swcJestConfig.swcrc = false;
|
||||||
|
|
||||||
|
export default {
|
||||||
|
displayName: '@triliumnext/desktop-e2e',
|
||||||
|
preset: '../../jest.preset.js',
|
||||||
|
globalSetup: '<rootDir>/src/support/global-setup.ts',
|
||||||
|
globalTeardown: '<rootDir>/src/support/global-teardown.ts',
|
||||||
|
setupFiles: ['<rootDir>/src/support/test-setup.ts'],
|
||||||
|
testEnvironment: 'node',
|
||||||
|
transform: {
|
||||||
|
'^.+\\.[tj]s$': ['@swc/jest', swcJestConfig],
|
||||||
|
},
|
||||||
|
moduleFileExtensions: ['ts', 'js', 'html'],
|
||||||
|
coverageDirectory: 'test-output/jest/coverage',
|
||||||
|
};
|
25
apps/desktop-e2e/package.json
Normal file
25
apps/desktop-e2e/package.json
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"name": "@triliumnext/desktop-e2e",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"private": true,
|
||||||
|
"nx": {
|
||||||
|
"implicitDependencies": [
|
||||||
|
"@triliumnext/desktop"
|
||||||
|
],
|
||||||
|
"targets": {
|
||||||
|
"e2e": {
|
||||||
|
"executor": "@nx/jest:jest",
|
||||||
|
"outputs": [
|
||||||
|
"{projectRoot}/test-output/jest/coverage"
|
||||||
|
],
|
||||||
|
"options": {
|
||||||
|
"jestConfig": "apps/desktop-e2e/jest.config.ts",
|
||||||
|
"passWithNoTests": true
|
||||||
|
},
|
||||||
|
"dependsOn": [
|
||||||
|
"@triliumnext/desktop:build"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
apps/desktop-e2e/src/desktop/desktop.spec.ts
Normal file
10
apps/desktop-e2e/src/desktop/desktop.spec.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
describe('GET /', () => {
|
||||||
|
it('should return a message', async () => {
|
||||||
|
const res = await axios.get(`/`);
|
||||||
|
|
||||||
|
expect(res.status).toBe(200);
|
||||||
|
expect(res.data).toEqual({ message: 'Hello API' });
|
||||||
|
});
|
||||||
|
})
|
11
apps/desktop-e2e/src/support/global-setup.ts
Normal file
11
apps/desktop-e2e/src/support/global-setup.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
var __TEARDOWN_MESSAGE__: string;
|
||||||
|
|
||||||
|
module.exports = async function() {
|
||||||
|
// Start services that that the app needs to run (e.g. database, docker-compose, etc.).
|
||||||
|
console.log('\nSetting up...\n');
|
||||||
|
|
||||||
|
// Hint: Use `globalThis` to pass variables to global teardown.
|
||||||
|
globalThis.__TEARDOWN_MESSAGE__ = '\nTearing down...\n';
|
||||||
|
};
|
||||||
|
|
7
apps/desktop-e2e/src/support/global-teardown.ts
Normal file
7
apps/desktop-e2e/src/support/global-teardown.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
|
||||||
|
module.exports = async function() {
|
||||||
|
// Put clean up logic here (e.g. stopping services, docker-compose, etc.).
|
||||||
|
// Hint: `globalThis` is shared between setup and teardown.
|
||||||
|
console.log(globalThis.__TEARDOWN_MESSAGE__);
|
||||||
|
};
|
9
apps/desktop-e2e/src/support/test-setup.ts
Normal file
9
apps/desktop-e2e/src/support/test-setup.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
module.exports = async function() {
|
||||||
|
// Configure axios for tests to use.
|
||||||
|
const host = process.env.HOST ?? 'localhost';
|
||||||
|
const port = process.env.PORT ?? '3000';
|
||||||
|
axios.defaults.baseURL = `http://${host}:${port}`;
|
||||||
|
};
|
14
apps/desktop-e2e/tsconfig.json
Normal file
14
apps/desktop-e2e/tsconfig.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../tsconfig.base.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "out-tsc/@triliumnext/desktop-e2e",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"noUnusedLocals": false,
|
||||||
|
"noImplicitAny": false
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"jest.config.ts",
|
||||||
|
"src/**/*.ts"
|
||||||
|
],
|
||||||
|
"references": []
|
||||||
|
}
|
@ -4,43 +4,6 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"nx": {
|
"nx": {
|
||||||
"targets": {
|
"targets": {
|
||||||
"build": {
|
|
||||||
"executor": "@nx/esbuild:esbuild",
|
|
||||||
"outputs": [
|
|
||||||
"{options.outputPath}"
|
|
||||||
],
|
|
||||||
"defaultConfiguration": "production",
|
|
||||||
"options": {
|
|
||||||
"platform": "node",
|
|
||||||
"outputPath": "apps/desktop/dist",
|
|
||||||
"format": [
|
|
||||||
"cjs"
|
|
||||||
],
|
|
||||||
"bundle": false,
|
|
||||||
"main": "apps/desktop/src/main.ts",
|
|
||||||
"tsConfig": "apps/desktop/tsconfig.app.json",
|
|
||||||
"assets": [
|
|
||||||
"apps/desktop/src/assets"
|
|
||||||
],
|
|
||||||
"esbuildOptions": {
|
|
||||||
"sourcemap": true,
|
|
||||||
"outExtension": {
|
|
||||||
".js": ".js"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"configurations": {
|
|
||||||
"development": {},
|
|
||||||
"production": {
|
|
||||||
"esbuildOptions": {
|
|
||||||
"sourcemap": false,
|
|
||||||
"outExtension": {
|
|
||||||
".js": ".js"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"serve": {
|
"serve": {
|
||||||
"executor": "@nx/js:node",
|
"executor": "@nx/js:node",
|
||||||
"defaultConfiguration": "development",
|
"defaultConfiguration": "development",
|
||||||
|
@ -1 +1,21 @@
|
|||||||
console.log('Hello World');
|
/**
|
||||||
|
* This is not a production server yet!
|
||||||
|
* This is only a minimal backend to get started.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import express from 'express';
|
||||||
|
import * as path from 'path';
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
|
||||||
|
app.use('/assets', express.static(path.join(__dirname, 'assets')));
|
||||||
|
|
||||||
|
app.get('/api', (req, res) => {
|
||||||
|
res.send({ message: 'Welcome to desktop!' });
|
||||||
|
});
|
||||||
|
|
||||||
|
const port = process.env.PORT || 3333;
|
||||||
|
const server = app.listen(port, () => {
|
||||||
|
console.log(`Listening at http://localhost:${port}/api`);
|
||||||
|
});
|
||||||
|
server.on('error', console.error);
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"outDir": "dist",
|
"outDir": "dist",
|
||||||
"types": [
|
"types": [
|
||||||
"node"
|
"node",
|
||||||
|
"express"
|
||||||
],
|
],
|
||||||
"rootDir": "src",
|
"rootDir": "src",
|
||||||
"tsBuildInfoFile": "dist/tsconfig.app.tsbuildinfo"
|
"tsBuildInfoFile": "dist/tsconfig.app.tsbuildinfo"
|
||||||
|
20
apps/desktop/webpack.config.js
Normal file
20
apps/desktop/webpack.config.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
const { NxAppWebpackPlugin } = require('@nx/webpack/app-plugin');
|
||||||
|
const { join } = require('path');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
output: {
|
||||||
|
path: join(__dirname, 'dist'),
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
new NxAppWebpackPlugin({
|
||||||
|
target: 'node',
|
||||||
|
compiler: 'tsc',
|
||||||
|
main: './src/main.ts',
|
||||||
|
tsConfig: './tsconfig.app.json',
|
||||||
|
assets: ["./src/assets"],
|
||||||
|
optimization: false,
|
||||||
|
outputHashing: 'none',
|
||||||
|
generatePackageJson: true,
|
||||||
|
})
|
||||||
|
],
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user