美文网首页
webpack.config.js 基础配置

webpack.config.js 基础配置

作者: 谢大见 | 来源:发表于2018-03-14 17:46 被阅读0次

webpack 中文文档

安装

二、安装webpack
使用webpack之前需要安装webpack,在这里我们需要在两个地方安装:全局目录和项目目录,在项目目录下执行以下命令:

//全局安装的作用是直接在命令行中使用
npm install -g webpack
//安装到项目目录,使用webpack的功能
npm install --save-dev webpack

完整的基础案例

webpack.config.js

const HtmlWebpackPlugin = require('html-webpack-plugin'); // 通过 npm 安装
const webpack = require('webpack'); // 用于访问内置插件
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;

相关文章

网友评论

      本文标题:webpack.config.js 基础配置

      本文链接:https://www.haomeiwen.com/subject/rutqqftx.html