gdsestimating / three-dxf

A dxf viewer for the browser using three.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support React

opened this issue · comments

Please, add support to React. If I install the dxf-parse, three and three-dxf, when I import all the modules in my React application:

import DxfParser from 'dxf-parser';

import * as THREE from 'three';

import * as ThreeDxf from 'three-dxf';

I receive an error, THREE is not defined. This error happens because the module three-dxf expect the THREE on global scope:

<script src='https://cdnjs.cloudflare.com/ajax/libs/three.js/101/three.js'></script>

To solve this issue I had import the Dxf Parse and Three Dxf on my React component and the Three in the index.html file. It could be cool to support React by default.

Good point. Been meaning to make it more versatile for a while but haven't done it yet. I just updated dxf-parser to be usable in any environment. I'll get to this library next.

I'm very close to supporting react I think. I added webpack to the project and updated the code to use es5 imports. The file that gets generated into the dist folder might not be react friendly. But I set up the library to point to the actual source in the case of something that supports es5 imports.

It'd be nice to package up everything into one es5 file in a way that react likes but there is a possibility it works as it is. I set up the package.json to point to the src/index.js file directly but I haven't really tested it. I'm just a react beginner so I'm not sure what more is required. Going to wait to publish until we figure this out.

I wonder what is the status of this issue at this stage and whether any help is needed?

I have finally gotten around to completing this. Try the latest version (1.0.1) and let me know if you have any trouble. I might eventually get my react sample up but not sure when.