Skip to content

Commit

Permalink
Merge pull request #10 from caoxiemeihao/v0.4.1
Browse files Browse the repository at this point in the history
V0.4.1
  • Loading branch information
caoxiemeihao authored Feb 18, 2023
2 parents f7b21c5 + ca4db34 commit e69967e
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 27 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 0.4.1 (2023-02-18)

#### Main Changed

- abf84f8 fix: types error #9

#### PR

- @Atinux docs: update options #8

## 0.4.0 (2023-02-15)

#### Main Changed
Expand Down
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
</p>

<div align="center">
<h1>nuxt-electron</h1>
<h1>Nuxt Electron</h1>
</div>
<p align="center">Integrate Nuxt and Electron</p>
<p align="center">
<a href="https://npmjs.org/package/nuxt-electron">
<img src="https://img.shields.io/npm/v/nuxt-electron.svg">
<img src="https://img.shields.io/npm/v/nuxt-electron.svg?colorA=18181B&colorB=28CF8D">
</a>
<a href="https://npmjs.org/package/nuxt-electron">
<img src="https://img.shields.io/npm/dm/nuxt-electron.svg">
<img src="https://img.shields.io/npm/dm/nuxt-electron.svg?colorA=18181B&colorB=28CF8D">
</a>
<img src="https://camo.githubusercontent.com/1355d11db24d82f2b23bbe4957178a05c7d5ca0948ddfc9eec38f5a6864fe4e5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6e7578742f6e7578742e7376673f7374796c653d666c617426636f6c6f72413d31383138314226636f6c6f72423d323843463844">
</p>

<br/>
Expand All @@ -28,10 +29,17 @@
1. Add the following dependency to your project

```sh
npm i -D nuxt-electron vite-electron-plugin electron electron-builder
# Using pnpm
pnpm add -D nuxt-electron vite-electron-plugin electron electron-builder

# Using yarn
yarn add --dev nuxt-electron vite-electron-plugin electron electron-builder

# Using npm
npm install --save-dev nuxt-electron vite-electron-plugin electron electron-builder
```

2. Add `nuxt-electron` to the modules section of `nuxt.config.ts`
2. Add `nuxt-electron` to the `modules` section of `nuxt.config.ts`

```ts
export default defineNuxtConfig({
Expand Down Expand Up @@ -62,23 +70,21 @@ Let's use the official [nuxt-starter-v3](https://codeload.github.com/nuxt/starte
└── tsconfig.json
```

## ElectronOptions
## Electron options

> This is based on the `vite-electron-plugin`, see the **[Documents](https://github.com/electron-vite/vite-electron-plugin#configuration)** for more detailed options
Here is the default `nuxt-electron` options

```ts
import type { ElectronOptions } from 'nuxt-electron'

export default defineNuxtConfig({
modules: [
'nuxt-electron'
],
electron: {
include: ['electron'],
outDir: 'dist-electron',
}
},
})
```

Expand Down
4 changes: 1 addition & 3 deletions examples/quick-start/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { ElectronOptions } from 'nuxt-electron'

export default defineNuxtConfig({
modules: [
['nuxt-electron', <ElectronOptions>{}],
'nuxt-electron',
],
})
19 changes: 9 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "nuxt-electron",
"version": "0.4.0",
"version": "0.4.1",
"description": "Nuxt Integration with Electron",
"main": "index.mjs",
"types": "types",
"main": "./dist/index.cjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": "./index.mjs",
"require": "./index.js"
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
}
},
"repository": {
Expand All @@ -17,9 +18,9 @@
"author": "草鞋没号 <[email protected]>",
"license": "MIT",
"scripts": {
"build": "npm run types && vite build",
"build": "vite build",
"dev": "vite build --watch",
"types": "rm -rf types && tsc -p tsconfig.build.json",
"types": "tsc -p tsconfig.build.json",
"prepublishOnly": "npm run build"
},
"peerDependencies": {
Expand All @@ -36,9 +37,7 @@
},
"files": [
"electron-env.d.ts",
"types",
"index.mjs",
"index.js"
"dist"
],
"keywords": [
"nuxt",
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {
startup,
} from 'vite-electron-plugin'

// Fix tsc build error
import { NuxtModule } from '@nuxt/schema'

export interface ElectronOptions extends Partial<Configuration> { }

export default defineNuxtModule<ElectronOptions>({
Expand Down Expand Up @@ -67,4 +70,4 @@ export default defineNuxtModule<ElectronOptions>({
}
})
}
}) as any
})
47 changes: 43 additions & 4 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import fs from 'node:fs'
import path from 'node:path'
import { spawn } from 'node:child_process'
import { builtinModules } from 'node:module'
import { defineConfig } from 'vite'
import { builtinModules } from 'module'
import pkg from './package.json'

export default defineConfig({
build: {
minify: false,
emptyOutDir: false,
outDir: '',
lib: {
entry: 'src/index.ts',
formats: ['cjs', 'es'],
fileName: format => format === 'es' ? '[name].mjs' : '[name].js',
fileName: format => format === 'es' ? '[name].mjs' : '[name].cjs',
},
rollupOptions: {
external: [
Expand All @@ -28,4 +29,42 @@ export default defineConfig({
},
},
},
plugins: [{
name: 'generate-types',
async closeBundle() {
removeTypes()
await generateTypes()
moveTypesToDist()
removeTypes()
},
}],
})

function removeTypes() {
fs.rmSync(path.join(__dirname, 'types'), { recursive: true, force: true })
}

function generateTypes() {
return new Promise(resolve => {
const cp = spawn(
process.platform === 'win32' ? 'npm.cmd' : 'npm',
['run', 'types'],
{ stdio: 'inherit' },
)
cp.on('exit', code => {
!code && console.log('[types]', 'declaration generated')
resolve(code)
})
cp.on('error', process.exit)
})
}

function moveTypesToDist() {
const types = path.join(__dirname, 'types')
const dist = path.join(__dirname, 'dist')
const files = fs.readdirSync(types).filter(n => n.endsWith('.d.ts'))
for (const file of files) {
fs.copyFileSync(path.join(types, file), path.join(dist, file))
console.log('[types]', `types/${file} -> dist/${file}`)
}
}

0 comments on commit e69967e

Please sign in to comment.