create-react-app下的@修饰器正确的使用方式记录
在create-react-app下使用es7的@修饰器会报错''Support for the experimental syntax 'decorators-legacy' isn't currently enable"
原文地址https://www.jianshu.com/p/b841aee4745f
需要做以下几步,首先正确安装babel
"devDependencies": {
"@babel/core": "^7.1.6",
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/plugin-proposal-decorators": "^7.1.6",
"@babel/preset-env": "^7.1.6",
}
.babelrc文件配置:
{
"presets": ["@babel/preset-env"],
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": true }],
["@babel/plugin-proposal-class-properties", { "loose": true }]
]
}
在pageage.json同级目录新建config-overrides.js并且添加内容
const { injectBabelPlugin } = require('react-app-rewired');
module.exports = function override(config, env) {
// do stuff with the webpack config...
config = injectBabelPlugin(['@babel/plugin-proposal-decorators', { "legacy": true }], config) //{ "legacy": true }一定不能掉,否则报错
return config;
};
安装react-app-rewired并且修改启动package.json
"scripts": {
- "start": "react-scripts start",
+ "start": "react-app-rewired start",
- "build": "react-scripts build",
+ "build": "react-app-rewired build",
- "test": "react-scripts test",
+ "test": "react-app-rewired test",
}
最后运行即可解决
作者:chouchou723
链接:https://www.jianshu.com/p/b841aee4745f
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
create-react-app下的@修饰器正确的使用方式记录的更多相关文章
- 深入 Create React App 核心概念
本文差点难产而死.因为总结的过程中,多次怀疑本文是对官方文档的直接翻译和简单诺列:同时官方文档很全面,全范围的介绍无疑加深了写作的心智负担.但在最终的梳理中,发现走出了一条与众不同的路,于是坚持分享出 ...
- 如何扩展 Create React App 的 Webpack 配置
如何扩展 Create React App 的 Webpack 配置 原文地址https://zhaozhiming.github.io/blog/2018/01/08/create-react-a ...
- 在 .NET Core 5 中集成 Create React app
翻译自 Camilo Reyes 2021年2月22日的文章 <Integrate Create React app with .NET Core 5> [1] Camilo Reyes ...
- tap news:week5 0.0 create react app
参考https://blog.csdn.net/qtfying/article/details/78665664 先创建文件夹 安装create react app 这个脚手架(facebook官方提 ...
- 使用create react app教程
This project was bootstrapped with Create React App. Below you will find some information on how to ...
- Create React App
Facebook开源了React前端框架(MIT Licence),也同时提供了React脚手架 - create-react-app. create-react-app遵循约定优于配置(Coc)的原 ...
- Create React App 安装less 报错
执行npm run eject 暴露模块 安装 npm i less less-loader -D 1.打开 react app 的 webpack.config.js const sassRege ...
- [React] Use the Fragment Short Syntax in Create React App 2.0
create-react-app version 2.0 added a lot of new features. One of the new features is upgrading to Ba ...
- [React] {svg, css module, sass} support in Create React App 2.0
create-react-app version 2.0 added a lot of new features. One of the new features is added the svgr ...
随机推荐
- Vue+Java实现在页面树形展示文件目录
getInfo.class /** * @author Sue * @create 2019-07-16 15:06 **/ @RestController public class getInfo ...
- Jmeter JDBC请求-----数据库读取数据进行参数化 通过SSH跳板机连接数据库
前期准备: jdbc驱动:mysql-connector-java-5.1.7-bin.jar Jmeter 要链接MySQL数据库,首选需要下载mysql jdbc驱动包(注:驱动包的版本一定要与你 ...
- JDK8以后接口是可以定义实现方法,必须需要default修饰符修饰
package com.company.java.oop.cls; interface IB { default void doMethod1() { System.out.println(" ...
- python爬虫——爬取淘票票正在热映电影
今天正好学习了一下python的爬虫,觉得收获蛮大的,所以写一篇博客帮助想学习爬虫的伙伴们. 这里我就以一个简单地爬取淘票票正在热映电影为例,介绍一下一个爬虫的完整流程. 首先,话不多说,上干货——源 ...
- Dynamic Programming and Policy Evaluation
Dynamic Programming divides the original problem into subproblems, and then complete the whole task ...
- 子页面中ifram高度自使用
HTML: <iframe id="mainframe" name="mainframe" style="width: 100%; border ...
- java8 语言特性
Lamda 表达式 使用内部类也可以实现相关的功能, 但使用lamda更简短 lamda 的参数类型可以省略 如果是单条语句, lamda 的花括号可以省略 如果是单条语句, lamda 的 retu ...
- WPF使用Mutex创建单实例程序失效
vs2019 1.引入名称空间 using System.Threading; using System.Runtime.InteropServices; 2.导入dll并声明方法 [DllImpor ...
- 如何创建Windows虚拟机
Windows虚拟机搭建 第1步:运行"Vmware WorkStation",看到主页面,创建新的虚拟机 第2步:新建虚拟机向导——典型(推荐) 第3步:选择光盘映像文件 第4步 ...
- jsp对象 指令 动作
转载来源:https://blog.csdn.net/u010897406/article/details/49618413 jsp九大内置对象:1>out 向客户端输出数据,字节流.如out. ...