zoukankan      html  css  js  c++  java
  • webpack学习笔记



    const path = require('path') //进度条 const ProgressBarPlugin = require('progress-bar-webpack-plugin'); const chalk = require('chalk'); // 以树图的方式展示打包后的文件 //const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; //输出html const HtmlWebpackPlugin = require('html-webpack-plugin') //抽离css插件 const MiniCssExtractPlugin = require("mini-css-extract-plugin") //清空dist const {CleanWebpackPlugin} = require('clean-webpack-plugin') module.exports = { mode: 'production', //模式 production :生产环境 development :开发环境 entry: './src/main.js', //入口文件 output:{ //输出路径 filename: 'bundle.js', path: path.resolve(__dirname, 'dist') //设置输出路径 dist }, devServer:{ //开发服务配置 port:3112, progress:true, contentBase:'./dist', compress: true }, devtool:'inline-source-map', //提示:追踪错误和警告 module:{ //允许指定多个loader rules:[ //模块筛选 {test: /.css$/, use:[MiniCssExtractPlugin.loader,"css-loader","postcss-loader"]}, {test: /.less$/, use :[MiniCssExtractPlugin.loader,"css-loader","postcss-loader","less-loader"]}, {test: /.scss$/, use :[MiniCssExtractPlugin.loader,"css-loader","postcss-loader","sass-loader"]}, { test:/.(png|jpg|gif)$/, use:[{ loader:'url-loader', options:{ limit:50000, //限制 outputPath:'images/' //输出路径 }} ] } ] }, plugins:[ //插件 new HtmlWebpackPlugin({ title:"lxl webpack demo", filename: 'index.html', //输出后的文件名 template: path.resolve(__dirname,'./public/index.html'), //指定引用模板 hash:true }), new CleanWebpackPlugin(), //清楚dist new ProgressBarPlugin({ // 显示进度 format: chalk.green('Progressing') + '[:bar]' + chalk.green(':percent') + '(:elapsed seconds)', clear: false }), new MiniCssExtractPlugin({ //分离css filename:'main.css' //指定输出后的文件名 }) // new BundleAnalyzerPlugin() ] }

     package.json

    {
      "name": "lxl-demo",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "build": "webpack --mode production",
        "start": "webpack --config webpack.config.js",
        "dev": "webpack-dev-server --open --mode development"
      },
      "author": "",
      "license": "ISC",
      "devDependencies": {
        "autoprefixer": "^9.7.1",
        "chalk": "^3.0.0",
        "clean-webpack-plugin": "^3.0.0",
        "css-loader": "^3.2.0",
        "file-loader": "^4.2.0",
        "html-webpack-plugin": "^3.2.0",
        "mini-css-extract-plugin": "^0.8.0",
        "node-sass": "^4.13.0",
        "postcss-cssnext": "^3.1.0",
        "postcss-loader": "^3.0.0",
        "progress-bar-webpack-plugin": "^1.12.1",
        "sass-loader": "^8.0.0",
        "style-loader": "^1.0.0",
        "url-loader": "^2.2.0",
        "webpack": "^4.41.2",
        "webpack-bundle-analyzer": "^3.6.0",
        "webpack-cli": "^3.3.10",
        "webpack-dev-server": "^3.9.0"
      }
    }

     postcss.config.js  

    //处理 css兼容前缀
    module.exports = { plugins: [ require('autoprefixer') ] }
  • 相关阅读:
    eCryptfs文件系统测试
    体验企业级网络管理软件(图片加视频)
    基于Linux2.6内核的加密容器法保护文件方法
    Orion Network Performance Monitor 软件在网络管理中的应用
    两款硬件代理服务器产品之比较
    3Com Network Supervisor与IBM Tivoli NetView两款网管软件操作视频
    成为IBM精英讲师-一分耕耘 一份收获 同时也多了一份责任!
    Hp Open View安装使用视频
    在Fedora 14 alpha 下测试Kvm情况(视频)
    ACM模板——分数类
  • 原文地址:https://www.cnblogs.com/linsxl/p/11834376.html
Copyright © 2011-2022 走看看