Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to integrate this library for ReactJS. Guidelines / Fix needed. #30

Closed
terence410 opened this issue Jan 4, 2021 · 4 comments
Closed

Comments

@terence410
Copy link

in the source code "const data = base64.toByteArray(fs.readFileSync(__dirname + '/classes.trie', 'base64'));"

since browser doesn't have fs.readFileSync supports, some pre build transform is needed to load the classes.tire during build time. Anyone has some guidelines how I can do this in ReactJS? Thanks!

-- recommendations for author , instead of loading the file using fs, we might use
// const data = base64.toByteArray(fs.readFileSync(__dirname + '/classes.trie', 'base64'));

// convert the classes.tire as base64 string in JS files
const classData = "AA4IAAAAAAAAAhqg5VV7NJtZvz7fTC8zU5d.........";
const data = base64.toByteArray(classData);

@blikblum
Copy link
Member

blikblum commented Jan 4, 2021

Try linebreak-next. When used with webpack or rollup should work

@terence410
Copy link
Author

thx. But that package is sort of clone of the original one, but fixing the fs.readFileSync issue. I think it will be great if Arthur can do the same as you do.

meanwhile, I am able to make it work using Webpack 5. In case any one wanted to fix the issues:

npm install transform-loader buffer --save

in webpack.config.js
module: {
rules: [
{ test: /.js$/, use: ["transform-loader?brfs"] }
],
},

In your .js file (transform-loader will load the file and replace it with base64 string and then use Buffer to convert back to the format it needed. However, buffer is not natively supported, so we need to include that package)

const {Buffer} = require("buffer");
const LineBreaker = require("linebreak");
const lorem = 'lorem ipsum...';
const breaker = new LineBreaker(lorem);

@blikblum
Copy link
Member

blikblum commented Jan 5, 2021

#18

@liborm85
Copy link
Contributor

liborm85 commented Jul 7, 2021

It is usually solved using brfs as mentioned above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants