webpack is a module bundler.webpack是一个模块打包工具,为了解决上篇一提到的各种模块加载或者转换的问题。

webpack takes modules with dependencies and generates static assets representing those modules.

webpack以依赖模块和生成 静态的资源来代表这些模块。

Goals

  • Split the dependency tree into chunks loaded on demand 把依赖树拆分成chunks,按需加载
  • Keep initial loading time low    保证初始加载时间少
  • Every static asset should be able to be a module   每个静态资源都应该是一个模块
  • Ability to  integrate 3rd-party libraries as modules    致力于整合第三方库作为模块
  • Ability to customize nearly every part of the module bundler 致力于自定义接近每一部分的模块打包器
  • Suited for big projects  适合大工程项目

How is webpack different?

这里说了webpack的特性

Code Splitting

webpack has two types of dependencies in its dependency tree: sync and async. Async dependencies act as split points and form a new chunk. After the chunk tree is optimized(优化), a file is emitted for each chunk.

Read more about Code Splitting.

Loaders

webpack can only process JavaScript natively, but loaders are used to transform other resources into JavaScript. By doing so, every resource forms a module.

Read more about Using loaders and Loaders. webpack只能处理原生js,但是loaders就是用来把其他的资源转换为js。这样做,每个资源都形成一个模块

Clever parsing

webpack has a clever parser that can process nearly every 3rd party library. It even allows expressions in dependencies like so require("./templates/" + name + ".jade"). It handles the most common module styles: CommonJs and AMD. webpack的巧妙地解析能处理几乎每一个第三方库。

Read more about expressions in dependencies, CommonJs and AMD.

Plugin system

webpack features a rich plugin system. Most internal features are based on this plugin system. This allows you to customize webpack for your needs and distribute common plugins as open source. webpack有功能丰富的插件系统。,很多内部特性都基于插件系统,它允许你按需自定义或以开源的形式分发公共插件。

Read more about Plugins.

Installation

node.js

Install node.js.

node.js comes with a package manager called npm.

webpack

webpack can be installed through npm:

$ npm install webpack -g

webpack is now installed globally and the webpack command is available.

先安装nodejs,用里面的包控制工具npm,然后用npm安装webpack,通过这个命令将webpack安装到全局,webpack这命令就可以用了。

Use webpack in a project

It’s the best to have webpack also as dependency in your project. Through this you can choose a local webpack version and will not be forced to use the single global one.最好把webpack写进dependency,你可以选一个webpack版本,并不强制用哪个。

Add a package.json configuration file for npm with: 通过这个命令加一个package.json文件

$ npm init

The answers to the questions are not so important if you don’t want to publish your project to npm.

Install and add webpack to the package.json with:     把webpack加入到package.json中,加入到dev里面。

$ npm install webpack --save-dev

Versions

There are two versions of webpack available. The stable one and a beta version. The beta version is marked with a -beta in the version string. The beta version may contain fragile changes or experimental features and is less tested. See changelog for differences. For serious stuff you should use the stable version:    webpack有俩版本可用,测试和稳定版。安装测试版要加 -beta的mark。测试版加入了一些测试的新特性。

$ npm install webpack@1.2.x --save-dev  

Dev Tools

If you want to use dev tools you should install it:  webpack的dev tools,下面是安装命令

$ npm install webpack-dev-server --save-dev

转载于:https://www.cnblogs.com/dh-dh/p/5165202.html

webpack入门(二)what is webpack相关推荐

  1. webpack入门(四)——webpack loader 和plugin

    什么是loader loaders是你用在app源码上的转换元件.他们是用node.js运行的,把源文件作为参数,返回新的资源的函数.  例如,你可以用loaders告诉webpack加载 coffe ...

  2. WEBPACK 入门

    webpack 入门 1. 什么是webpack 官网介绍:webpack是一个模块打包器.webpack 处理带有依赖关系的模块,生成一系列表示这些模块的静态资源.(webpack is a mod ...

  3. webpack入门学习手记(一)

    本人微信公众号:前端修炼之路,欢迎关注. 之前用过gulp.grunt,但是一直没有学习过webpack.这两天刚好有时间,学习了下webpack.webpack要想深入研究,配置的东西比较多,网上的 ...

  4. webpack入门学习手记(一) 1

    本人微信公众号:前端修炼之路,欢迎关注. 之前用过gulp.grunt,但是一直没有学习过webpack.这两天刚好有时间,学习了下webpack.webpack要想深入研究,配置的东西比较多,网上的 ...

  5. Webpack入门——使用Webpack打包Angular项目的一个例子

    (一)什么是Webpack Webpack是一个前端的模块管理工具(module bundler),以下是webpack的官网:http://webpack.github.io/,一进入官网可以看到下 ...

  6. (三)webpack入门——webpack功能集合的demo

    ErduYang 自律的人生才自由 博客园 首页 新随笔 联系 订阅 管理 随笔 - 37文章 - 0评论 - 8 (三)webpack入门--webpack功能集合的demo 此篇文章来源于http ...

  7. webpack入门学习手记(三)

    本人微信公众号:前端修炼之路,欢迎关注. 距离上一次更新这个系列,过去了两天.最近实在是有点忙,没有挤出时间整理.感觉日更还真是困难? 以下是正文. 管理资源 如果看过之前的系列文章,应该会有一个学习 ...

  8. webpack入门之简单例子跑起来

    webpack入门之简单例子跑起来 webpack介绍 Webpack是当下最热门的前端资源模块化管理和打包工具,它可以将很多松散的模块按照依赖和规则打包成符合生产环境部署的前端资源,还可以将按需加载 ...

  9. webpack入门--前端必备

    什么是 webpack? webpack是一款模块加载器兼打包工具,它能把各种资源,例如JS(含JSX).coffee.样式(含less/sass).图片等都作为模块来使用和处理.我们可以直接使用 r ...

最新文章

  1. Nucleus SE RTOS初始化和启动
  2. 如何查看服务器一个端口的占用情况(netstat -an)
  3. HashMap 1.7工作原理
  4. String类(二)
  5. linux下防火墙加白名单
  6. java中容易混淆的方法_java中容易混淆的概念
  7. 飞鸽传书2013年开发计划
  8. AngularJS国际化配置
  9. 一支python教学_第一只python爬虫
  10. insertAfter函数
  11. 关于codesmith及其相关资源--破解的
  12. Spark算子:RDD键值转换操作(5)–leftOuterJoin、rightOuterJoin、subtractByKey
  13. C语言双人贪吃蛇游戏瘦身版本
  14. 数独-- 一个高效率生成数独的算法
  15. nRF24L01+ 数据手册
  16. 最详细职场面试题目(一)
  17. 正则匹配两个字符之间的字符串
  18. Apache 实现AJAX跨域请求
  19. 浏览器被强制修改成 桔梗网—Google, Firefox
  20. AMD completes ATI acquisition

热门文章

  1. 兼容Silverlight4的实用的Silverlight可拖放工具类源代码
  2. OpenCV 【十四】改变图像的对比度和亮度高度关联章节:OpenCV 【十】——Gamma校正 ——图像灰度变化
  3. C++拾趣——STL容器的插入、删除、遍历和查找操作性能对比(ubuntu g++)——遍历和查找
  4. Windows/Linux TCP Socket网络编程简介及测试代码
  5. linux怎么注册信息,linux device注册
  6. java观察者模式_Java设计模式之观察者模式详解
  7. php禁止代理ip访问_php禁止某ip或ip地址段访问的方法
  8. linux如何设置awesome字体,Awesome简单配置
  9. ps怎么把一个颜色替换成另一个颜色_图标设计,用PS制作一款小清新的拟物时钟...
  10. java c++的区别_Java语言与C、C++之间的区别?