webpack.config.js的代码——20170406

来源:4-5 使用 less 和 sass

aSuncat

2017-04-06 22:53

var htmlWebpackPlugin=require('html-webpack-plugin');
var webpack=require('webpack');
var path=require('path');
module.exports={
    context:__dirname,
    entry:'./src/app.js',
    output:{
        path:path.resolve(__dirname,'./dist'),
        filename:'js/[name].bundle.js'
    },
    module:{
      rules:[
          {
              test:/\.js$/,
              loader:'babel-loader',
              exclude:path.resolve(__dirname,'/node_modules/'),//已经引用过的,已经打包过的文件
              include:path.resolve(__dirname,'/src/'),
              query:{
                  presets:['latest']
              }
          },
          {
              test:/\.css$/,
              use:[
                  {
                      loader:'style-loader'
                  },
                  {
                      loader:'css-loader',
                      options:{
                          importLoaders:1
                      }
                  },
                  {
                      loader:'postcss-loader'
                  }
              ]
          },
          {
              test:/\.less$/,
              use:[
                  'style-loader',
                  'css-loader',
                  'postcss-loader',
                  'less-loader'
              ]
          },
          {
              test:/\.scss$/,
              use:[
                  'style-loader',
                  'css-loader',
                  'postcss-loader',
                  'sass-loader'
              ]
          }
      ]
    },
    plugins:[
        new htmlWebpackPlugin({
            filename:'index.html',
            template:'index.html',
            inject:'body'
        }),
        new webpack.LoaderOptionsPlugin({
            options:{
                postcss:function(){
                    return [
                        require('autoprefixer')({
                            broswers:['last 5 versions']
                        })
                    ]
                }
            }
        })
    ]
};


写回答 关注

4回答

  • 慕粉0057303747
    2017-04-08 11:34:55
    已采纳

    不错,写得好,棒极了

  • Mr_Blue_001
    2017-06-09 15:41:57

    为嘛楼主的代码粘到我这里,post-loader始终不起作用??蓝瘦香菇

  • 不浪漫
    2017-05-12 01:22:12

    new webpack.LoaderOptionsPlugin({

                options:{

                    postcss:function(){

                        return [

                            require('autoprefixer')({

                                broswers:['last 5 versions']

                            })

                        ]

                    }

                }

            })

        ]

    这玩意我的不管怎么弄 都起不了作用

    慕盖茨858...

    我也遇到相同的问题,不报错,但是无效果,如果知道原因了,麻烦告诉一下!谢谢!

    2017-05-24 17:11:49

    共 3 条回复 >

  • 最初的梦想gawin
    2017-04-07 15:14:40

    图片压缩没有 。。。

webpack深入与实战

webpack实战教程,用真实项目带你探索 webpack 强大的功能

86561 学习 · 721 问题

查看课程

相似问题