简体   繁体   中英

webpack function usage after bundling

I try to pack that https://www.npmjs.com/package/@jscad/dxf-deserializer library and use in browser. Uage from node looks like

const deSerializer = require('@jscad/dxf-deserializer')
const rawData = fs.readFileSync('PATH/TO/file.dxf')
const jscadCode = deSerializer(rawData)

How should i use that now after linking bundle script?

I had tried

let objs = deserialize(fileText,'square10x10',{output: 'csg'})

and got

ReferenceError: deserialize is not defined

There is js test file works fine with node

const fs = require('fs')
const path = require('path')
const test = require('ava')
const { CSG, CAG } = require('@jscad/csg')

const { nearlyEqual } = require( '../../../test/helpers/nearlyEqual' )

const { deserialize } = require( '../index' )

const samples = path.resolve('../../node_modules/@jscad/sample-files')

//
// Test suite for DXF deserialization (import)
//
test('ASCII DXF from Bourke 3D Entities to Object Conversion', t => {
  //const dxfPath = path.resolve(__dirname, '../../../../sample-files/dxf/bourke/3d-entities.dxf')
  const dxfPath = path.resolve(samples, 'dxf/bourke/3d-entities.dxf')
  t.deepEqual(true, fs.existsSync(dxfPath))

  let dxf = fs.readFileSync(dxfPath, 'UTF8')
  let objs = deserialize(dxf,'aaa',{output: 'objects'})

// expect one layer, containing 2 objects (CSG, and Line3D)
  t.true(Array.isArray(objs))
  t.is(objs.length,2)
})

Try Adding

node: {
   fs: "empty"
}

fs module isn't defined in the browser. Maybe that's what stopping deserialize from been created. With a try.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM