2019-10-15 最新 webpack.config.js 配置

const path = require("path");
const webpack = require("webpack");
const htmlWebpack = require("html-webpack-plugin");
const uglifyjsWebpack = require("uglifyjs-webpack-plugin");
const { VueLoaderPlugin } = require('vue-loader');

module.exports={
    entry:"./mian.js",
    output:{
        path:path.resolve(__dirname,"dist"),
        filename:"index-[hash:5].js"
    },
    // mode:development,
    module:{
        rules:[
            {
                test:/\.css$/,
                use:["style-loader","css-loader"]
            },
            {
                test:/\.less$/,
                use:["style-loader","css-loader","less-loader"]
            },
            {
                test:/\.(png|jpg|gif|jpeg|bmp)$/,
                use:["url-loader?limit=7654&name=[hash:8]-[name].[ext]"]
            },
            {
                test:/\.(ttf|eot|svg|woff|woff2)$/,
                use:["url-loader"]
            },
            {
                test:/\.scss$/,
                use:["style-loader","css-loader","sass-loader"]
            },
            {
                test:/\.vue$/,
                use:["vue-loader"]
            },
            {
                test: /\.m?js$/,
                exclude: /(node_modules|bower_components)/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['@babel/preset-env',"@babel/preset-react"],
                        plugins: ['@babel/plugin-transform-runtime',"@babel/plugin-transform-arrow-functions", "@babel/plugin-proposal-class-properties" ]
                    }
                }
            }
        ]
    },
    plugins:[
        new htmlWebpack({
            filename:"index.html",
            template:"./index.html"
        }),
        new VueLoaderPlugin(),
        new uglifyjsWebpack(),
        new webpack.HotModuleReplacementPlugin()
    ],
    devServer:{
        contentBase:path.join(__dirname,"./index.html"),
        compress:true,
        port:8080,
        hot:true,
        proxy:{
             '/api': {

                target: 'https://c.y.qq.com/',

                changeOrigin: true,

                pathRewrite: {'^/api' : ''} 

              }


        }
    },
    resolve:{
        alias:{
            //可以改变安装包默认指向的js文件
            "vue$":"vue.dist/vue.js" //修改vue被导入时候的包的路径
        }
    }
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 2019-08-29 15777116666 字数 328 · 阅读 12 2019-08-29 02:43 姓名...
    07e3340d4f7b阅读 138评论 0 0
  • 自我反省或者是扪心自问,肯定不能推卸自己的问题,年轻时候是问题少年,年长后一定不会好转。所以最近感觉自己很暴躁,也...
    海边的桃源阅读 118评论 0 0
  • They are in their time zone,and you are in yours. 前些天在考虑高...
    秋河七阅读 127评论 1 1
  • 1.感谢自己在昨晚很晚开线上会议睡得很晚,今天依然坚持早起带线上舞动课程,感恩自己的如约而至,谢谢,谢谢,谢谢 2...
    舞动精灵Yummy阅读 55评论 0 0
  • 最近看了好多关于江歌的报道,一个花一样的女孩损命日本,原因就是她为了保护自己的室友。然而她的室友却悄然消失大半年,...
    就是有点文艺范儿阅读 296评论 0 0