Различия
Показаны различия между двумя версиями страницы.
Предыдущая версия справа и слева Предыдущая версия Следующая версия | Предыдущая версия | ||
electron [2024/12/18 09:47] – mirocow | electron [2025/02/14 16:11] (текущий) – mirocow | ||
---|---|---|---|
Строка 1: | Строка 1: | ||
- | {{tag> | + | {{tag> |
====== Electron ====== | ====== Electron ====== | ||
Строка 14: | Строка 14: | ||
* [[tailwindcss]] | * [[tailwindcss]] | ||
* [[CodeMirror]] | * [[CodeMirror]] | ||
+ | * [[vscode]] | ||
====== Electron + Webpack 4 + Babel 7 + React 16 + PostCSS + Sass + Ant Design + Jest + Enzyme + Eslint ====== | ====== Electron + Webpack 4 + Babel 7 + React 16 + PostCSS + Sass + Ant Design + Jest + Enzyme + Eslint ====== | ||
Строка 26: | Строка 27: | ||
====== Electron + React + Typescript + Visual Studio Code ====== | ====== Electron + React + Typescript + Visual Studio Code ====== | ||
+ | |||
+ | ===== Создание проекта ===== | ||
+ | |||
+ | <code bash> | ||
+ | $ npm install --save-dev @babel/core @babel/ | ||
+ | $ npm install --save react react-dom | ||
+ | $ npm install --save-dev @types/ | ||
+ | $ npm install --save-dev eslint @eslint/js typescript typescript-eslint | ||
+ | $ npm install eslint eslint-plugin-react eslint-plugin-jest eslint-plugin-html \ | ||
+ | eslint-plugin-json eslint-plugin-filenames eslint-plugin-react-hooks \ | ||
+ | eslint-plugin-import eslint-plugin-simple-import-sort --save-dev | ||
+ | </ | ||
+ | |||
+ | ===== Внесение правок ===== | ||
+ | |||
+ | <code typescript> | ||
+ | // webpack.rules.js | ||
+ | module.exports = [ | ||
+ | // ... existing loader config ... | ||
+ | { | ||
+ | test: /\.jsx?$/, | ||
+ | use: { | ||
+ | loader: ' | ||
+ | options: { | ||
+ | exclude: / | ||
+ | presets: [' | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | // ... existing loader config ... | ||
+ | ]; | ||
+ | </ | ||
+ | |||
+ | <code typescript> | ||
+ | // src/app.jsx | ||
+ | import * as React from ' | ||
+ | import { createRoot } from ' | ||
+ | |||
+ | const root = createRoot(document.body); | ||
+ | root.render(< | ||
+ | |||
+ | // src/ | ||
+ | import ' | ||
+ | </ | ||
+ | |||
+ | <code typescript> | ||
+ | // src/app.tsx | ||
+ | import { createRoot } from ' | ||
+ | |||
+ | const root = createRoot(document.body); | ||
+ | root.render(< | ||
+ | |||
+ | // src/ | ||
+ | import ' | ||
+ | </ | ||
launch.js | launch.js | ||
Строка 114: | Строка 170: | ||
} | } | ||
] | ] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Сборка ==== | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | <code bash> | ||
+ | $ esr --cache ./ | ||
+ | $ cross-env USE_HARD_LINKS=false electron-builder build --config electron-builder.config.js --dir | ||
+ | </ | ||
+ | |||
+ | esbuild.main.ts | ||
+ | <code javascript> | ||
+ | import esbuild from ' | ||
+ | import { builtinModules } from ' | ||
+ | import path from ' | ||
+ | |||
+ | import pkg from ' | ||
+ | |||
+ | interface Options { | ||
+ | mode?: ' | ||
+ | } | ||
+ | |||
+ | export default async function build(options: | ||
+ | // Код сборки | ||
+ | const mode = options.mode || ' | ||
+ | const __DEV__ = mode !== ' | ||
+ | const PORT = pkg.dev[' | ||
+ | |||
+ | const outdir = __DEV__ | ||
+ | ? path.join(__dirname, | ||
+ | : path.join(__dirname, | ||
+ | | ||
+ | const env: Record< | ||
+ | ? { | ||
+ | ' | ||
+ | `http:// | ||
+ | ), | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | } | ||
+ | : { | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | }; | ||
+ | const preload = esbuild.build({ | ||
+ | entryPoints: | ||
+ | outfile: path.join(outdir, | ||
+ | target: ' | ||
+ | bundle: true, | ||
+ | platform: ' | ||
+ | sourcemap: true, | ||
+ | format: ' | ||
+ | external: [' | ||
+ | }); | ||
+ | const main = esbuild.build({ | ||
+ | entryPoints: | ||
+ | outfile: path.join(outdir, | ||
+ | bundle: true, | ||
+ | platform: ' | ||
+ | sourcemap: true, | ||
+ | format: ' | ||
+ | define: env, | ||
+ | external: [ // ? | ||
+ | ' | ||
+ | ' | ||
+ | ...Object.keys(pkg.dependencies), | ||
+ | ...Object.keys(builtinModules), | ||
+ | ], | ||
+ | }); | ||
+ | return Promise.all([main, | ||
+ | } | ||
+ | | ||
+ | // Build if ran as a cli script | ||
+ | const isMain = require.main === module; | ||
+ | |||
+ | if (isMain) { | ||
+ | const mode = | ||
+ | process.env.NODE_ENV === ' | ||
+ | build({ mode }); | ||
} | } | ||
</ | </ | ||
Строка 159: | Строка 298: | ||
* https:// | * https:// | ||
+ | * https:// | ||
+ | |||
====== Документы ====== | ====== Документы ====== |