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 dependenciesCommonJs 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

webpack入门(二)what is webpack的更多相关文章

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

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

  2. webpack入门教程之Hello webpack(一)

    webpack入门教程系列为官网Tutorials的个人译文,旨在给予想要学习webpack的小伙伴一个另外的途径.如有不当之处,请大家指出. 看完入门教程系列后,你将会学习到如下内容: 1.如何安装 ...

  3. webpack入门指南(基于webpack v4.41.2)

    2019年12月5日初稿,目前webpack已经更新到v4.41.2,本文正是基于该版本,在windows8.1操作系统下进行的demo编译,适用于想入门webpack的前端开发人员. webpack ...

  4. 玩转webpack(二):webpack的核心对象

    欢迎大家前往云+社区,获取更多腾讯海量技术实践干货哦~ 作者介绍:陈柏信,腾讯前端开发,目前主要负责手Q游戏中心业务开发,以及项目相关的技术升级.架构优化等工作. 前言 webpack 是一个强大的模 ...

  5. webpack入门(三)webpack的api

    终于到了webpack api这一篇,我都等不及了0.0; webpack is fed a configuration object. Depending on your usage of webp ...

  6. webpack入门(一)webpack的动机 ---前端专业英语

    记得某次考试,出国N年老师出的卷子全是英语,坑的英语不好的我们不要不要的.幸亏上了专业英语课.最重要的是专业英语对于我们很重要,比如webpack,一堆博客都是几小时入门,如何会用webpack,当你 ...

  7. webpack入门(一)——webpack 介绍

    如今的网站正在演化为web应用程序: 1. 越来越多的使用JavaScript. 2. 现代浏览器提供更广泛的接口. 3. 整页刷新的情况越来越少,甚至更多代码在同一个页面.(SPA) 因此有很多代码 ...

  8. webpack入门(五)webpack CLI

    webpack的CLI安装和命令 Installation $ npm install webpack -g The webpack command is now available globally ...

  9. webpack入门(四)webpack的api 2 module

    接着介绍webpack的module. module Options affecting the normal modules (NormalModuleFactory)  这些选项影响普通的模块 m ...

  10. Webpack 入门指南 - 3. Hello, Angular2!

    Webpack 入门指南 - 1.安装 Webpack 入门指南 - 2.模块 这一次,我们使用 Webpack 来打包 Angular 2 的应用. 与官方的 Hello, Angular 2 项目 ...

随机推荐

  1. vue2.0生命周期

    https://www.cnblogs.com/goloving/p/8616989.html(copy )

  2. leetcode:Roman to Integer and Integer to Roman

    2015-06-03 罗马数字以前接触过I到VIII比较多,直到遇见这个题目才知道更详细.阿拉伯数字和罗马数字之间的转换最重的是了解罗马数字的规则. 罗马数字规则:(总结) 1, 罗马数字共有7个,即 ...

  3. 剑指offer(19)二叉树中和为某一值的路径

    题目: 输入一颗二叉树的跟节点和一个整数,打印出二叉树中结点值的和为输入整数的所有路径.路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径.(注意: 在返回值的list中,数组长度大的 ...

  4. 在JavaEE中使用Hibernate框架

    我们必须要了解一些Hibernate基础对象,如下: 配置对象 配置对象是你在任何 Hibernate 应用程序中创造的第一个 Hibernate 对象,并且经常只在应用程序初始化期间创造.它代表了 ...

  5. java获取本机ip(排除虚拟机等一些ip)最终解,总算找到方法了

    本文参考https://blog.csdn.net/u011809209/article/details/77236602 本文参考https://blog.csdn.net/yinshuomail/ ...

  6. uname -r查询版本不是安装的版本的问题

    uname -r 查出来的版本与/lib/modules下面的内核版本不匹配.啥原因? 第一步,先strace uname -r看看这个uname -r到底从哪里获取的版本. strace没有看出来 ...

  7. Alertmanager 安装(k8s报警)

    一.下载Alertmanager https://prometheus.io/download/ wget https://github.com/prometheus/alertmanager/rel ...

  8. RestTemplate proxy 设置方式

    RestTemplate restTemplate = new RestTemplate(new SimpleClientHttpRequestFactory() {{ setProxy(new ja ...

  9. 手机连接WiFi有感叹号x怎么回事?如何消除手机WiFi感叹号?

    经过多年的革新,现在的安卓系统已经非常优秀了,某些程度已经超越iOS,卡顿和耗电也不再是安卓系统的代名词了.而为了体验到最优秀的安卓系统,不少人都会购买海外的手机,因为海外手机的安卓系统都比较精简,非 ...

  10. 【python练习题】程序17

    #题目:输入一行字符,分别统计出其中英文字母.空格.数字和其它字符的个数. s = input('请输入字符串:') alf = 0 space = 0 digi = 0 other = 0 for ...