小编Tal*_*ofe的帖子

是否可以创建一个仅编译为平台代码的 Electorn 应用程序?

我将针对一个非常具体的用例来澄清我的问题。

假设我的代码设计如下:

在此输入图像描述

这是内容:

src/inner/inner.darwin.ts:

export default function logger() {
    console.log('Darwin Logger');
}
Run Code Online (Sandbox Code Playgroud)

src/inner/inner.windows.ts:

export default function logger() {
    console.log('Windows Logger');
}
Run Code Online (Sandbox Code Playgroud)

src/inner/inner.ts:

注意导出默认值 - 这是强制性的

import LOGGER from '???????????';

export default class A {
    public static logger() {
         LOGGER();
    }
}
Run Code Online (Sandbox Code Playgroud)

所以基本上,当我编译 Windows 代码时,我想导入代码inner.windows.ts。使用Mac时代码-inner.darwin.ts代码。

我确实知道我可以控制tsconfig.json. 因此,当我要创建 Windows 应用程序时,我将编写以下代码:

"exclude": ["**/*.darwin.ts"]
Run Code Online (Sandbox Code Playgroud)

当我创建 Mac 时:

"exclude": ["**/*.windows.ts"]
Run Code Online (Sandbox Code Playgroud)

然而,这并没有帮助解决进口问题。

我确实知道我可以运行依赖于底层平台的代码process.platform,但它不能完成这项工作。我希望输出的 Windows 应用程序尺寸更小 - 并忽略任何 Mac 代码。如果我使用它process.platform- Mac 代码仍然存在于底层 Windows 应用程序中。

有什么建议吗?

Webpack 能帮上忙吗?我愿意接受任何代码更改,只要代码定义良好并拆分即可,最终结果是我只有 …

javascript typescript electron

11
推荐指数
1
解决办法
227
查看次数

无法运行 Vitest 测试并出现错误:“Vitest 在测试运行期间捕获 1 个未处理的错误”

我有一个函数,我尝试使用 Vitest 进行测试。

\n

这是我的功能(我测试导出的功能):

\n
import os from \'node:os\';\n\nimport { AI_COMMIT_IGNORED_FILES } from \'../constants/ai-commit\';\nimport { asyncExec } from \'./os\';\n\n/**\n * The function returns array of files paths that are in staged mode\n * @returns array of files paths in staged mode\n */\nconst getStagedFiles = async () => {\n    const gitCommand = \'git diff --name-only --cached --relative .\';\n    const { stdout: filesOutput, stderr } = await asyncExec(gitCommand);\n\n    if (stderr) {\n        throw new Error(stderr);\n    }\n\n    const filesList = filesOutput.split(os.EOL).filter(Boolean);\n\n    return filesList;\n};\n\n\n/**\n …
Run Code Online (Sandbox Code Playgroud)

javascript testing typescript vitest

10
推荐指数
1
解决办法
6864
查看次数

如何让nestjs监视特定的节点模块?

在我的应用程序中,我想让 NestJS 在特定节点模块发生更改后重新加载开发模式。

我运行这个脚本:nest build --watch

我的nest-cli.json文件是:

{
    "$schema": "https://json.schemastore.org/nest-cli",
    "collection": "@nestjs/schematics",
    "sourceRoot": "src",
    "compilerOptions": {
        "webpack": true,
        "webpackConfigPath": "./webpack.config.js",
        "deleteOutDir": true
    }
}
Run Code Online (Sandbox Code Playgroud)

我的 webpack 文件是:

const nodeExternals = require('webpack-node-externals');
const { RunScriptWebpackPlugin } = require('run-script-webpack-plugin');

const { version } = require('../../package.json');

const configuration = (options, webpack) => ({
    ...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: [/\.d\.ts$/],
        }),
        new RunScriptWebpackPlugin({ name: options.output.filename, autoRestart: false …
Run Code Online (Sandbox Code Playgroud)

webpack nestjs

6
推荐指数
0
解决办法
270
查看次数

SWR 突变不会使用类的静态方法作为获取器来更新缓存

我正在使用该swr包。我成功地使用 获取数据useSWR,但是当我尝试改变数据时 - 它不起作用,并且 的缓存状态swr不会改变(正如它应该的那样)。

我创建了自定义钩子:

import useSWR from 'swr';

import BackendService from '@/services/backend';

const useBackend = <D, E = unknown>(path: string | null) => {
    const { data, error, isLoading, mutate } = useSWR<D, E>(path, BackendService.get);

    return { data, error, isLoading, mutate };
};

export default useBackend;
Run Code Online (Sandbox Code Playgroud)

这是我的BackendService

import { preload } from 'swr';

import type { IHttpMethod } from '@/interfaces/http';

class BackendService {
    private static routesWithRefreshToken: string[] = ['/user/auth'];

    private …
Run Code Online (Sandbox Code Playgroud)

javascript typescript reactjs swr

6
推荐指数
1
解决办法
2154
查看次数

“webpack-cli”:无法加载“webpack.config.ts”配置,TypeError [ERR_UNKNOWN_FILE_EXTENSION]:未知的文件扩展名“.ts”

我有一个 TypeScript 项目,我使用 Webpack 将代码转换为 JavaScript。

\n

我的版本:

\n
    "devDependencies": {\n        "@commitlint/cli": "17.0.2",\n        "@exlint.io/inflint": "1.2.9",\n        "@types/inquirer": "8.2.1",\n        "@types/micromatch": "4.0.2",\n        "@types/minimist": "1.2.2",\n        "@types/webpack-node-externals": "2.5.3",\n        "@typescript-eslint/eslint-plugin": "5.58.0",\n        "@typescript-eslint/parser": "5.58.0",\n        "chalk": "5.2.0",\n        "commitizen": "4.2.4",\n        "cz-vinyl": "1.3.2",\n        "depcheck": "1.4.3",\n        "eslint": "8.38.0",\n        "eslint-config-prettier": "8.8.0",\n        "eslint-plugin-deprecation": "1.4.1",\n        "eslint-plugin-import": "2.27.5",\n        "eslint-plugin-node": "11.1.0",\n        "eslint-plugin-unused-imports": "2.0.0",\n        "figlet": "1.5.2",\n        "husky": "8.0.1",\n        "is-ci": "3.0.1",\n        "lint-staged": "13.0.1",\n        "npm-run-all": "4.1.5",\n        "prettier": "2.6.2",\n        "rimraf": "3.0.2",\n        "ts-loader": "9.4.2",\n        "ts-node": "10.9.1",\n        "tsconfig-paths-webpack-plugin": "4.0.1",\n        "typescript": "5.0.4",\n        "webpack": "5.78.0",\n        "webpack-cli": "5.0.1",\n        "webpack-node-externals": "3.0.0",\n        "webpack-shell-plugin-next": "2.3.1"\n    }\n
Run Code Online (Sandbox Code Playgroud)\n

我运行以下命令: …

javascript typescript webpack

5
推荐指数
1
解决办法
3213
查看次数

标签 统计

javascript ×4

typescript ×4

webpack ×2

electron ×1

nestjs ×1

reactjs ×1

swr ×1

testing ×1

vitest ×1