Различия
Показаны различия между двумя версиями страницы.
Предыдущая версия справа и слева Предыдущая версия Следующая версия | Предыдущая версия | ||
electron [2023/10/14 22:14] – mirocow | electron [2025/02/14 16:11] (текущий) – mirocow | ||
---|---|---|---|
Строка 1: | Строка 1: | ||
+ | {{tag> | ||
+ | |||
====== Electron ====== | ====== Electron ====== | ||
+ | |||
+ | * [[vite]] | ||
+ | * [[nedb]] | ||
+ | * [[node-gyp]] | ||
+ | * [[node-libcurl]] | ||
+ | * [[leveldb]] | ||
+ | * [[esr]] | ||
+ | * [[tsc]] | ||
+ | * [[esbuild]] | ||
+ | * [[nunjucks]] | ||
+ | * [[tailwindcss]] | ||
+ | * [[CodeMirror]] | ||
+ | * [[vscode]] | ||
+ | |||
+ | ====== Electron + Webpack 4 + Babel 7 + React 16 + PostCSS + Sass + Ant Design + Jest + Enzyme + Eslint ====== | ||
+ | |||
+ | <code json> | ||
+ | </ | ||
+ | |||
+ | ====== Electron + VueJs + Typescript + Visual Studio Code ====== | ||
+ | |||
+ | <code json> | ||
+ | </ | ||
+ | |||
+ | ====== 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 | ||
+ | <code json> | ||
+ | { | ||
+ | // Use IntelliSense to learn about possible attributes. | ||
+ | // Hover to view descriptions of existing attributes. | ||
+ | // For more information, | ||
+ | " | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ] | ||
+ | }, | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | tasks.js | ||
+ | <code json> | ||
+ | { | ||
+ | // See https:// | ||
+ | // for the documentation about the tasks.json format | ||
+ | " | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | tsconfig.json | ||
+ | <code json> | ||
+ | { | ||
+ | // Use IntelliSense to learn about possible attributes. | ||
+ | // Hover to view descriptions of existing attributes. | ||
+ | // For more information, | ||
+ | " | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ] | ||
+ | }, | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | ], | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ] | ||
+ | } | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Сборка ==== | ||
+ | |||
+ | [[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 }); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | webpack.config.js | ||
+ | <code javascript> | ||
+ | module.exports = { | ||
+ | entry: " | ||
+ | output: { | ||
+ | filename: " | ||
+ | //path: __dirname + "/ | ||
+ | }, | ||
+ | mode: " | ||
+ | |||
+ | // Enable sourcemaps for debugging webpack output. | ||
+ | devtool: " | ||
+ | |||
+ | resolve: { | ||
+ | // Add ' | ||
+ | extensions: [" | ||
+ | }, | ||
+ | |||
+ | module: { | ||
+ | rules: [ | ||
+ | // All files with a ' | ||
+ | { test: /\.tsx?$/, loader: " | ||
+ | |||
+ | // All output ' | ||
+ | { enforce: " | ||
+ | ] | ||
+ | }, | ||
+ | |||
+ | // When importing a module whose path matches one of the following, just | ||
+ | // assume a corresponding global variable exists and use that instead. | ||
+ | // This is important because it allows us to avoid bundling all of our | ||
+ | // dependencies, | ||
+ | externals: { | ||
+ | // " | ||
+ | // " | ||
+ | }, | ||
+ | }; | ||
+ | </ | ||
+ | |||
+ | ====== Boilerplate ====== | ||
+ | |||
+ | * https:// | ||
+ | * https:// | ||
+ | |||
+ | |||
+ | ====== Документы ====== | ||
+ | |||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | |||
+ | ====== Ссылки ====== | ||
+ | |||
- [[Electron: | - [[Electron: |