vite-plugin / vite-plugin-native Goto Github PK
View Code? Open in Web Editor NEWInspired by rollup-plugin-natives
License: MIT License
Inspired by rollup-plugin-natives
License: MIT License
vite.config.ts
plugins: [
native({
outDir: '../../dist/main',
map(mapping) {
if (mapping.id === 'koffi.node') {
const m = /\/([^/]+)\/koffi.node$/.exec(mapping.native)
if (m) {
console.log(mapping.output, m[1])
mapping.output = mapping.output.replace('koffi.node', `${m[1]}.node`)
// mapping.id = `./${m[1]}.node`
mapping.id = `./darwin_x64.node`
}
console.log(mapping)
}
return mapping
},
target: 'cjs'
})
],
generated index.js
const $o = require('./darwin_x64.node'),
Lo = Object.freeze(Object.defineProperty({ __proto__: null, default: $o }, Symbol.toStringTag, { value: 'Module' })),
Ce = La(Lo)
/* --- */
function La(r) {
if (r.__esModule) return r
var t = r.default
if (typeof t == 'function') {
var e = function i() {
return this instanceof i ? Reflect.construct(t, arguments, this.constructor) : t.apply(this, arguments)
}
e.prototype = t.prototype
} else e = {}
return (
Object.defineProperty(e, '__esModule', { value: !0 }),
Object.keys(r).forEach(function (i) {
var n = Object.getOwnPropertyDescriptor(r, i)
Object.defineProperty(
e,
i,
n.get
? n
: {
enumerable: !0,
get: function () {
return r[i]
}
}
)
}),
e
)
}
As shown above, it seems that the required object is just put inside default. I'm not sure this is a bug of this plugin or the vite.
I follow the example of serialport.
{
entry: "electron/worker.ts",
onstart(option) {
option.reload()
},
vite: {
build: {
rollupOptions: {
external: ['sqlite3', "better-sqlite3"]
},
},
plugins: [
native({
outDir: 'dist-electron',
})
]
}
}
but error occurs like bellow:
node:fs:1396
handleErrorFromBinding(ctx);
^
Error: ENOENT: no such file or directory, mkdir '/Auto-Defect-Detect/defect-detect/D:/Auto-Defect-Detect/defect-detect/dist-electron'
at Object.mkdirSync (node:fs:1396:3)
at configResolved (D:\Auto-Defect-Detect\defect-detect\node_modules\.store\[email protected]\node_modules\vite-plugin-native\dist\index.js:143:12)
at file:///D:/Auto-Defect-Detect/defect-detect/node_modules/.store/[email protected]/node_modules/vite/dist/node/chunks/dep-df561101.js:65946:28
at Array.map (<anonymous>)
at resolveConfig (file:///D:/Auto-Defect-Detect/defect-detect/node_modules/.store/[email protected]/node_modules/vite/dist/node/chunks/dep-df561101.js:65946:14)
at async Module.build (file:///D:/Auto-Defect-Detect/defect-detect/node_modules/.store/[email protected]/node_modules/vite/dist/node/chunks/dep-df561101.js:47852:20) {
errno: -4058,
syscall: 'mkdir',
code: 'ENOENT',
path: '/Auto-Defect-Detect/defect-detect/D:/Auto-Defect-Detect/defect-detect/dist-electron'
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.