- React 16 Essentials(Second Edition)
- Artemij Fedosejev Adam Boduch
- 361字
- 2021-07-02 22:25:20
Reusing Node.js modules
As I mentioned earlier, there will be a step in our development process called building. During this step, our build script will take our source files and all our Node.js dependency packages and transform them into a single file that web browsers can successfully execute. The most important part of this building process is called packaging. But what do we need to package and why? Let's think about it. I briefly mentioned earlier that we're not creating a Node.js application, but yet we're talking about reusing Node.js modules. Does this mean that we'll be reusing Node.js modules in a nonNode.js application? Is that even possible? It turns out that there is a way of doing this.
Webpack is a tool used for bundling all your dependency files together in such a way that you can reuse Node.js modules in client-side JavaScript applications. You can learn more about Webpack at http://webpack.js.org. To install Webpack, run the following command from inside the ~/snapterest/
directory:
npm install --save-dev webpack
Notice the --save-dev
flag. It tells npm to add Webpack to our package.json
file as a development dependency. Adding a module name to our package.json
file as a dependency allows us to record what dependencies we're using, and we can easily install them later with the npm install
command, if needed. There is a distinction between the dependencies that are required to run your application and the ones that are required to develop your application. Webpack is used at build time, and not at runtime, so it's a development dependency. Hence, the use of the --save-dev
flag. If you check the content of your package.json
file now, you'll see this (don’t worry if your Webpack version doesn’t match exactly):
"devDependencies": { "webpack": "^2.2.1" }
Notice that npm created a new folder in your ~/snapterest/
directory called node_modules
. This is the place where it puts all your local dependency modules.
Congrats on installing your first Node.js module! Webpack will allow us to use Node.js modules in our client-side JavaScript applications. It will be a part of our build process. Now let's take a closer look at our build process.
- R語言數據可視化實戰
- Android NDK Beginner’s Guide
- Learning Neo4j 3.x(Second Edition)
- Building Cross-Platform Desktop Applications with Electron
- Java程序設計:原理與范例
- Teaching with Google Classroom
- Learning Concurrent Programming in Scala
- 搞定J2EE:Struts+Spring+Hibernate整合詳解與典型案例
- JBoss:Developer's Guide
- Django實戰:Python Web典型模塊與項目開發
- Python 3 數據分析與機器學習實戰
- Photoshop CC移動UI設計案例教程(全彩慕課版·第2版)
- 物聯網系統架構設計與邊緣計算(原書第2版)
- 虛擬現實建模與編程(SketchUp+OSG開發技術)
- Java設計模式深入研究