• webpack 常用的loader


    1.npm init 创建一个node的包文件
    
    2.npm install webpack webpack-cli -g  全局安装不推荐
    
    
    3.npx webpakc -v 查看webpack的版本号   npx 实在当前项目的node_modules里面查找,npm  是在全局查找
    
    4.npm info webpack 可以查看所有的webpack的包
    
    5.npm install webpack@4.16.6 webpack-cli -D  安装指定版本
    
    6.默认webpack 打包寻找的配置文件是webpack.config.js 如果想更改文件夹名字:npx webpack --config webpack.js(这是需要更改文件夹的名字)

    常用的loader插件webpack.config.js配置,注意插件是从上到下,从左到右执行

       const path = require('path')
       module.exports = {
        mode:'development',
        entry:'./src/index.js',
        module:{
            rules:[
                {
                    test:/.(jpg|png|gif)$/,
                    use:{
                        loader:'file-loader',
                        options:{
                            name:'[name].[ext]',
                            outputPath:'images/'
                        }
                    }
                },
                {
                    test:/.css$/,
                    use:['style-loader','css-loader','postcss-loader']
                },
                {
                    test:/.scss$/,
                    use:['style-loader','css-loader','sass-loader']
                }
            ]
        },
          output:{
            filename:'bound.js',
            path:path.resolve(__dirname,'dist')
         }

        }
     
    2.postcss-loader 用来给添加厂商前缀的 ,需要安装在根目录下添加postcss-config.js的配置文件   npm install autoprefixer -D 
       postcss-config.js 配置:
       module.exports ={
        plugins:require('autoprefixer')
       }
      效果如下:
     
    1. -webkit-transform: translate(100px,100px);
    2. transform: translate(100px,100px);
     3.css 打包扩展:
      {
                    test:/.css$/,
                    use:[
                        'style-loader',
                        {
                            loader:'css-loader',
                            options:{
                                importLoaders:2  //执行css-loader之前会先执行下面两个loader postcss-loader, sass-loader
                                modules:true  //开启css 模块化打包,样式只是针对当前页面
                            }
                        },
                        'sass-loader',
                        'postcss-loader'
                    ]
                }
     



  • 相关阅读:
    Win10解决RuntimeBroker.exe后台运行CPU占比高的方法
    easyexcel测试用例
    电脑Wlan不能上网的解决办法
    [LeetCode] Delete and Earn 删除与赚取
    [LeetCode] Daily Temperatures 日常温度
    [LeetCode] 738. Monotone Increasing Digits 单调递增数字
    [LeetCode] 737. Sentence Similarity II 句子相似度之二
    [LeetCode] Parse Lisp Expression 解析Lisp表达式
    [LeetCode] Asteroid Collision 行星碰撞
    [LeetCode] 644. Maximum Average Subarray II 子数组的最大平均值之二
  • 原文地址:https://www.cnblogs.com/huanhuan55/p/11832014.html
Copyright © 2020-2023  润新知