react+webpack+mobx的项目创建
问题描述
在创建项目的过程中,装饰器语法总是提示不能解析
自己尝试过哪些方法
在网上搜到很多关于支持修饰器的配置方法,在即也是了很多,下面是代码,但总是报错
相关代码
.babelrc
{
"presets": ["env","react"],
"plugins": [
"transform-decorators-legacy",
"transform-class-properties"
]
}
.package.json
{
"name": "mobx-demo",
"version": "0.1.0",
"private": true,
"dependencies": {
"mobx": "^5.0.3",
"mobx-react": "^5.2.3",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-scripts": "1.1.4",
"webpack": "^4.16.1",
"webpack-dev-server": "^3.1.4"
},
"scripts": {
"start": "webpack-dev-server --mode development --config build/webpack.config.js",
"dev": "webpack --mode development --config build/webpack.config.js",
"build": "webpack --mode production --config build/webpack.config.js"
},
"devDependencies": {
"babel-loader": "^7.1.5",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-decorators-legacy": "^1.3.5",
"babel-preset-env": "^1.7.0",
"babel-preset-mobx": "^1.0.3",
"html-webpack-plugin": "^3.2.0",
"webpack-cli": "^3.0.8"
},
"plugins": [
"transform-decorators-legacy",
"transform-class-properties"
]
}
错误代码
ERROR in ./src/entry/main.js 8:4
Module parse failed: Unexpected character '@' (8:4)
You may need an appropriate loader to handle this file type.
| class Todo {
| // id = Math.random();
> @observable title;
| @observable finished = false;
| constructor(title){
@ multi (webpack)-dev-server/client?http://localhost:8081 ./src/entry/main.js main[1]
你期待的结果是什么?
希望大神可以指导下我的配置是否哪里有问题,或者能指导我重新新建一个react+webpack+mobx项目 从头开始越详细越好。。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
webpack配置文件
之前按需引入ui库css 在.babelrc中配置有问题 在百度参考好多文章都没解决
最后在package.json中配置好了
@ 装饰器也配好了
使用 蚂蚁金服 npm i antd-mobile@next --save
网址: https://mobile.ant.design/ind...
按需引入antd-mobile的css npm i babel-plugin-import --save
在package.json中配置 找到这个
"babel": { "presets": [ "react-app" ] },
// 配置成下面这个样子 单引号改为双引号 没引号改为双引号 这时打开页面 你会发现配置好了按需加载 "babel": { "presets": [ "react-app" ], "plugins": [ ["import", { "libraryName": "antd-mobile", "style": "css" }] ] },
redux 使用 npm i redux --save
使用 npm i redux-thunk --save 异步处理事件避免store嵌套 redux默认处理同步 异步需要使用redux-thunk中间键
不使用store.subscribe 来提交数据 下载 npm i react-redux -S(是--save的简写)
这是Babel 6的一个插件,用于复制Babel 5中的旧装饰器行为
https://www.npmjs.com/package...
npm i babel-plugin-transform-decorators-legacy --save-dev 修饰器
在package.json 中配置:
"plugins": [
]