简体   繁体   中英

Pre-processing Nodejs script with javascript

I have created a nodejs script which access the DOM of html file and get an element by id. Now i need to generate a Javascript file equivalent to my nodejs script (like do browserify) so i can integrate it in my javascript program.

So i'm searching any solution to integrate my nodejs script in javascript program

Assuming you didn't use any Node.js-specific APIs, a simple ES6 to ES5 transpiler should do the job. In that case checkout Babel .

Babel quick usage guide:

npm install -g babel babel-preset-es2015

babel --presets es2015 YOUR_JS_FILE > OUTPUT_FILE

If you do make use of require calls and other Node.js shenanigans, then checkout Browserify which is more involved but will do what you want and bundle up any node modules you're using.

Browserify quick usage guide:

npm install -g browserify
browserify YOUR_JS_FILE -o OUTPUT_FILE

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