I have been coding with a React frontend and a Node/Express backend. But sometimes, I only need some plain Javascript without React, but still want the benefit of NPM and other Node modules. What is a way to do this?
You'll need a module bundler of some kind. There are many options including Webpack , Browserify, Gulp, and Parcel.
For Webpack, for example, from their example docs, the process could be:
Install webpack with npm install webpack
and install webpack-cli
Install a module you want to use on the frontend, eg lodash
In src/index.js
, import lodash: import _ from 'lodash';
and use it as needed. (You can also import other modules from NPM or from other places in your source code)
Set up webpack.config.js
if you need custom build configuration settings
Run webpack to build the project: npx webpack
. A single bundled JavaScript file will be created which contains all your source code and the imported Lodash's source code.
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.