博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
react 使用webpack打包问题汇总
阅读量:7199 次
发布时间:2019-06-29

本文共 2885 字,大约阅读时间需要 9 分钟。

一、TypeError: src\foo.js: Cannot read property 'bindings' of null 问题原因: 1.babel-loader一系列包的版本不兼容有冲突,需要检查版本,下面是能够成功运行的版本的版本组合: "@babel/plugin-proposal-class-properties": "^7.1.0", "babel-core": "^7.0.0-bridge.0", "babel-loader": "^7.1.5", "babel-preset-env": "^2.0.0-alpha.20", "babel-preset-es2015": "^7.0.0-beta.3", "babel-preset-react": "^7.0.0-beta.3", 2.rules配置的时候没有将node_modules exclude掉, 例子:

{                test: /\.js?$/,                exclude: path.resolve(__dirname, "node_modules"),                include: path.resolve(__dirname, "src"),                use: {                    loader: 'babel-loader',                    options: {                        presets: ['env', 'react'],                        plugins: [                            ["@babel/plugin-proposal-class-properties", { "loose": true }]                        ]                    },                }}复制代码

二、工程中涉及到antd框架的时候,应该如何配置?

const path = require('path');const HtmlWebpackPlugin = require('html-webpack-plugin');module.exports = {    mode: "development",    entry: path.resolve(__dirname, "./src/index.js"),    output: {        path: path.resolve(__dirname, "dist")    },    devServer: {        contentBase: path.join(__dirname, "dist"),        compress: true,        port: 3000    },    resolve: {        extensions: ['.js', '.jsx', '.less']    },    module: {        rules: [            {                test: /\.css?$/,                include: [path.join(__dirname, 'src'), path.join(__dirname, 'node_modules/antd')],                use: [ 'style-loader', 'css-loader']            },            {                test: /\.less?$/,                include: [path.join(__dirname, 'src'), path.join(__dirname, 'node_modules/antd')],                use: {                    loader: "less-loader",                    options:{                        javascriptEnabled: true                    }                }            },            {                test: /\.js?$/,                use: {                    loader: 'babel-loader',                    options: {                        presets: ['env', 'react'],                        plugins: [                            ["@babel/plugin-proposal-class-properties", { "loose": true }],["import", { "libraryName": "antd", "style": "css" }],#按需加载antd里面的组件                        ]                    },                }            },            {                test: /\.(ico|png|svg|jpg|gif)$/,                exclude: path.resolve(__dirname, "node_modules"),                include: path.resolve(__dirname, "src"),                use: [                    {                        loader: 'file-loader',                        options: {}                    }                ]            }        ]    },    plugins: [        new HtmlWebpackPlugin({template: './public/index.html'})    ]};复制代码

转载于:https://juejin.im/post/5ce39230f265da1bcf5db065

你可能感兴趣的文章
安装PHP扩展eaccelerator加速器
查看>>
SVN 学习
查看>>
SmartSVN设置ignoreList
查看>>
ios-网址中的中文或者非法字符转换
查看>>
白话SpringCloud | 第零章:前言
查看>>
XMind中的“任务信息”视图
查看>>
OSChina 双十一乱弹 ——来自单身狗的哀鸣
查看>>
OSChina 周三乱弹 ——我们职业更好的名字:爱码士
查看>>
左边的项目管理器不见了
查看>>
android 获取唯一标识
查看>>
HTML5 - Server-Sent Events
查看>>
网络研讨会的邀请:网络公开课_守护好数据库的备份信息
查看>>
使程序在Linux下后台运行
查看>>
关于赋值语句的一点看法
查看>>
windows版本的Emacs 无法显示图片的解决方法
查看>>
Discuz! 经典加密解密函数(带详解)
查看>>
JVM内存结构和6大区域
查看>>
centos6 Docker桥接到主机所在的内网
查看>>
C++ 动态内存
查看>>
网络安装CentOS5.5Final
查看>>