Giter Site home page Giter Site logo

vite-plugin-native's People

Contributors

caoxiemeihao avatar yejimeiming avatar

Stargazers

 avatar  avatar  avatar  avatar

vite-plugin-native's Issues

Native module is wrapped in to default

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.

Use native better-sqlite3 Error

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'
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.