Webpack

Webpack是一个针对JavaScript应用的打包工具,它按以下步骤来执行打包过程:

  1. 第归的扫描应用
  2. 根据扫描为应用构造一个包括所有模块的依赖关系图
  3. 根据关系图打包所有模块到一个或多个捆绑保(bundles)

Webpack包括4个核心概念

  • 入口(Entry)
  • 输出(Output)
  • 装载(Loaders)
  • 插件(Plugins)

请参看下面例子:

const HtmlWebpackPlugin = require('html-webpack-plugin'); //installed via npm
const webpack = require('webpack'); //to access built-in plugins
const 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: /\.txt$/, use: 'raw-loader' }
    ]
  },
  plugins: [
    new webpack.optimize.UglifyJsPlugin(),
    new HtmlWebpackPlugin({template: './src/index.html'})
  ]
};

module.exports = config;

 

posted @ 2017-11-02 09:09  Jinzd  阅读(121)  评论(0编辑  收藏  举报