1.Concepts:

webpack is a module bundler for modern JS applications. Since there are lots of complex JS code and dependencies of files.

2. Entry:
webpack provide a graph of application dependencies, the starting point is known as the entry point, which tells webpack where to start and follows the graph of dependencies to know what to bundle.

Can be specified in webpack.config.js:

  entry: "./app/entry", // string | object | array
entry: ["./app/entry1", "./app/entry2"],
entry: {
a: "./app/entry-a",
b: ["./app/entry-b1", "./app/entry-b2"]
},
// Here the application starts executing
// and webpack starts bundling

3. Output

Once you've bundled your assests together, we need to tell webpack where to bundle our application. the "output" property tells webpack how to treat bundled code.

Can be specified in webpack.config.js:

var path = require('path');

module.exports = {
entry: './path/to/my/entry/file.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'my-first-webpack.bundle.js'
}
};

Through output.filename and output.path, we're describing to webpack the name of our bundles, and where we want to emit it.

4. Loaders:

Goal is have all the assets in your project to be webpack's concern instead of browser's. This does not mean that we have to bundle all files together.

webpack treats every file(.css, .js, .html, .scss) as a module, but webpack only understand javascript.

Loaders in webpack transform these files into modules, as they are added to your dependency graph.

They have two purpose in your webpack config:

1) Identify what files should be transformed by a certain loader.(test property)

2) Tansform that file so that it can be added to the dependency graph(and eventually your bundle).(use property)

Can be specified in webpack.config.js:

var path = require('path');

const config = {
entry: './path/to/my/entry/file.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'my-first-webpack.bundle.js'
},
module: {
rules: [
{test: /\.(js|jsx)$/, use: 'babel-loader'}
]
}
}; module.exports = config;

In the above configuration, we defined a rule property for a single module, with required two properties: test and rules, this tells webpack compiler the following:

"Hey webpack compiler, when you come across a path that resolves to a '.js' or '.jsx' file inside of a require()/import statement, use the babel-loader to transform it before you add it to the bundle".

Important: define rules in modules.rules, not in rules.

5. Plugins:

Since Loaders execute per-file, plugins are backbones of webpack. A webpack plugins is a JS object that has an apply property, This apply property is called by the webpack compiler, give access to entire compilication process

i.e. Customize the webpack build process in a variety of ways.

If we want to use plugins or loaders, install them through npm, and then add instances in "plugins"(an array) properties .

var webpack = require('webpack')
// importing plugins that do not come by default in webpack
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var DashboardPlugin = require('webpack-dashboard/plugin'); // adding plugins to your configuration
plugins: [
// build optimization plugins
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: 'vendor-[hash].min.js',
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
drop_console: false,
}
}),
new ExtractTextPlugin({
filename: 'build.min.css',
allChunks: true,
}),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
// compile time plugins
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"',
}),
// webpack-dev-server enhancement plugins
new DashboardPlugin(),
new webpack.HotModuleReplacementPlugin(),
]

查看错误信息:

webpack --display-error-details

打包:

webpack --config webpack.config.js

填坑webpack的更多相关文章

  1. vue+node.js+webpack开发微信公众号功能填坑——v -for循环

    页面整体框架实现,实现小功能,循环出数据,整体代码是上一篇 vue+node.js+webpack开发微信公众号功能填坑--组件按需引入 修改部门代码 app.vue <yd-flexbox&g ...

  2. 各种报错各种坑 webpack让我在学习的过程中一度想要放弃

    由于拓展部分不是必须的,只是可以增强用户体验,但是有些时候页面给分页预留的位置不够,这个时候我们就可以通过设置来除去这一部分 子分区由两种创建方法,一种是不定义每个子分区子分区的名字和路径由分区决定, ...

  3. 使用vue开发微信公众号下SPA站点的填坑之旅

    原文发表于本人博客,点击进入使用vue开发微信公众号下SPA站点的填坑之旅 本文为我创业过程中,开发项目的填坑之旅.作为一个技术宅男,我的项目是做一个微信公众号,前后端全部自己搞定,不浪费国家一分钱^ ...

  4. Vue2.0 新手完全填坑攻略——从环境搭建到发布

    Jinkey原创感谢 showonne.yubang 技术指导Demo 地址:http://demo.jinkey.io/vue2源码:https://github.com/Jinkeycode/vu ...

  5. Vue填坑(1)----通过vue-cli,认识vue-router

    开始 首先,确保之前已经安装过 npm 和 nodejs(为了避免版本的问题,最好使用较新的版本). 全局安装 vue-cli : npm install -g vue-cli 新建文件夹 my-pr ...

  6. Android—基于微信开放平台v3SDK,开发微信支付填坑。

    接触微信支付之前听说过这是一个坑,,,心里已经有了准备...我以为我没准跳坑出不来了,没有想到我填上了,调用成功之后我感觉公司所有的同事都是漂亮的,隔着北京的大雾霾我仿佛看见了太阳~~~好了,装逼结束 ...

  7. css 填坑常用代码分享

    以下是常用的代码收集,没有任何技术含量,只是填坑的积累.转载请注明出处,谢谢. 因为提交比较麻烦,后来转置github:https://github.com/jsfront/src/blob/mast ...

  8. 填坑系列:通过ESXi来配置IPMI

    近日西安的天气很不错,可是看到从其他地方迁移来的主机在新环境下无法远程调试怪郁闷的,这就需要填坑,要不就会给后来者挖更大的坑. 今天遇到的坑是在IPMI的网络设置里面启用了VLAN标签之后,在新环境下 ...

  9. Node学习笔记(四):gulp+express+io.socket部署angularJs2(填坑篇)

    这篇就先暂停下上篇博客--你画我猜的进度,因为在做这个游戏的时候,想采用最新的ng2技术,奈何坑是一片又一片,这边就先介绍下环境部署和填坑史 既然要用ng2,首先要拿到资源,我这边用的是angular ...

随机推荐

  1. C++类数组批量赋值

    类和结构体不同,结构体在初始化时可以使用{...}的方法全部赋值,但是结构体怎么办呢?一种是把数据数组写到一个相同的结构体内,然后for循环使用一个非构造函数写入到类数组中.另一种方法是直接写入到对应 ...

  2. LeetCode 24——两两交换链表中的节点

    1. 题目 2. 解答 新建一个哨兵结点作为头结点,然后每次交换相邻两个结点.并依次将它们连接到新链表中去,再将原链表中后面的结点也串到新链表后面.直至到达链尾或者剩余一个节点,则此时返回新链表的头结 ...

  3. Python 3 学习笔记之——错误和异常

    1. 语法错误 Python 的语法错误被称为解析错,语法分析器会指出出错的代码行,并且在最先找到的错误的位置标记一个小小的箭头. >>> while True File " ...

  4. java设计模式之适配器模式以及在java中作用

    适配器作用就是讲一个接口适配到另一个接口,在Java 的I/O类库中有很多这样的需求,如将字符串数据转变成字节数据保存到文件中,将字节数据转变成流数据等. 以InputStreamReader和Out ...

  5. Z.XML第一次迭代分数分配

    紧张的第一次迭代落下帷幕,便到了分数分配这样令人揪心又无奈的日子.如何进行分数分配,以使大家都能满意,这一直是个难以非常好地处理的问题.幸运地是,我们团队的所有成员每个人都对本次迭代乃至整个项目过程付 ...

  6. UVA 437 The Tower of Babylon(DAG上的动态规划)

    题目大意是根据所给的有无限多个的n种立方体,求其所堆砌成的塔最大高度. 方法1,建图求解,可以把问题转化成求DAG上的最长路问题 #include <cstdio> #include &l ...

  7. PAT 1090 危险品装箱

    https://pintia.cn/problem-sets/994805260223102976/problems/1038429484026175488 集装箱运输货物时,我们必须特别小心,不能把 ...

  8. 算法(4) Rotate Image

    题目:把一个N×N的矩阵旋转90° 思路:这个题目折腾了好长时间,确切地说是两个小时!这道题也反映出自己的逻辑比较混乱 这道题我到底卡在了哪里?自己已经在本子上画出了一个转移的关系 a[0][0] - ...

  9. Java中动态代理实现原理深究

    一.前言 笔者平时开发使用“动态代理”不多,最近在看设计模式的时候,“动态代理”又在面前晃了几次,所以这次想从源码的角度去分析动态代理的实现原理,以窥探其精妙~ 二.正文 2.1 静态代理  本文源码 ...

  10. password & Encryption

    password & Encryption cipher https://dev.tencent.com/login