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 ...
随机推荐
- docker远程访问TLS证书认证shell
docker开启远程访问端口,防止非法访问 配置证书认证 配置防火墙或安全策略 #!/bin/bash # docker.tls.sh # 环境centos 7 ,root # 创建 Docker T ...
- linux挂载磁盘以及扩容主分区
新买的服务器,如果系统安装操作不当,可能会由于系统主分区过小,后期安装软件过多就会导致软件无法正常运行的问题,如果不做系统格式化,就需要通过购买新的硬盘来进行挂载和扩容主分区以解决问题.本文主要介绍l ...
- 【MM系列】SAP MM模块-组织结构第二篇
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP MM模块-组织结构第二篇 ...
- java中java.util.Date和java.sql.Date之间的关系和使用选择
关系: java.util.Date是java.sql.Date的父类 区别:(java.sql.Date包含年月日信息,java.util.Date包含年月日时分秒) 1:“规范化”的java.sq ...
- 20190902 On Java8 第十六章 代码校验
第十六章 代码校验 你永远不能保证你的代码是正确的,你只能证明它是错的. 测试 测试覆盖率的幻觉 测试覆盖率,同样也称为代码覆盖率,度量代码的测试百分比.百分比越高,测试的覆盖率越大. 当分析一个未知 ...
- spring data jpa 使用SQL语句查询
package com.ytkj.entity; import javax.persistence.*; import java.io.Serializable; /** * @Entity * 作用 ...
- Java核心技术
[Java核心技术36讲]1.谈谈你对Java平台的理解 2.Exception和Error有什么区别 3.谈谈final.finally.finalize有什么不同?4.强引用.软引用.弱引用.虚引 ...
- kafka+hbase+hive实现实时接入数据至hive
整体架构: 项目目标,实现配置mysql,便可以自动化入湖至Hive,入湖至Hive方便后期数据分析. 首先在Mysql中配置好kafka的topic.Server以及入户表等信息,java程序初始化 ...
- day20 博客系统开发
setting 文件加入 AUTH_USER_MODEL = "app名称.UserInfo" from django.db import models # Create ...
- Rest_Framework的视图与路由
视图与路由 drf除了在数据序列化部分简写代码以外,还在视图中提供了简写操作.所以在django原有的django.views.View类基础上,drf封装了多个子类出来提供给我们使用. Django ...