修复和解决方案:
感谢长话短说的@BoyWithSilver,以下是我为解决问题所做的:
-
补充。“减少到扩展部分”
-
删除了网页包中不必要的代码。配置。json例如删除了提取文本网页包插件
-
从3.0.1降级到2.7.0,修复了大量错误:索引中未定义的长度。antd中的文件更少。
更新3
这是我的包裹。json
{
"name": "mobx-reactjsx",
"version": "1.0.0",
"description": dfsdfsdfsd",
"scripts": {
"start": "webpack-dev-server --config webpack.config.js --progress --inline",
"lint": "eslint src"
},
"keywords": [
"react",
"reactjs",
"boilerplate",
"mobx",
"starter-kit",
"firebase",
"re-base"
],
"author": "Winston Fan",
"license": "MIT",
"homepage": "https://horizontalvision.azurewebsites.net/",
"devDependencies": {
"autoprefixer": "^8.0.0",
"babel-core": "^6.9.1",
"babel-loader": "^7.1.2",
"babel-plugin-import": "^1.6.4",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-es2015": "^6.9.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-1": "^6.5.0",
"css-loader": "^0.28.9",
"extract-text-webpack-plugin": "^3.0.2",
"less": "^3.0.1",
"less-loader": "^4.0.5",
"less-vars-to-js": "^1.2.1",
"postcss-loader": "^2.1.0",
"style-loader": "^0.20.2",
"webpack": "^3.5.5",
"webpack-dev-server": "^2.7.1"
},
"dependencies": {
"antd": "^3.2.1",
"firebase": "^4.9.1",
"mobx": "^3.5.1",
"mobx-react": "^4.4.1",
"mobx-react-devtools": "^4.2.15",
"re-base": "^3.2.2",
"react": "^16.2.0",
"react-dom": "^16.2.0"
}
}
更新2:
-
删除上下文选项后:
//上下文:路径。解析(\uu dirname,'dist'),
在网页中。配置。js公司
-
补充
javascriptEnabled:true
在网页包的较少加载程序下。配置。json
我收到了这些错误。
中出错/node\u modules/antd/lib/button/style/index。更少的模块构建
失败:
/*stylelint禁用
声明前面有空格,没有重复的选择器*/^无法读取
未定义的属性“length”
在F:\temp\playway\mobx reactjsx\node\u modules\antd\lib\style\color\bezierEasing中。较少的
(第1行,第1列)@/node\u modules/antd/lib/button/style/index。js公司
5:0-23 @ ./src/索引。js@多
(网页包)-开发服务器/客户端?
http://localhost:8080
./src/索引。js公司
中出错/node\u modules/antd/lib/style/index。更少模块生成失败:
/*stylelint禁用
声明前面有空格,没有重复的选择器*/^无法读取
未定义的属性“length”
在F:\temp\playway\mobx reactjsx\node\u modules\antd\lib\style\color\bezierEasing中。较少的
(第1行,第1列)@/node\u modules/antd/lib/button/style/index。js公司
3:0-33 @ ./src/索引。js@多
(网页包)-开发服务器/客户端?
http://localhost:8080
./src/索引。js公司
中出错/node\u modules/antd/lib/style/index。更少模块生成失败:
ModuleBuildError:模块生成失败:
/*stylelint禁用
声明前面有空格,没有重复的选择器*/^无法读取
未定义的属性“length”
在F:\temp\playway\mobx reactjsx\node\u modules\antd\lib\style\color\bezierEasing中。较少的
(第1行第1列)
在RunLoader上(F:\temp\playway\mobx reactjsx\node\u modules\webpack\lib\NormalModule.js:195:19)
位于F:\temp\playway\mobx reactjsx\node\u modules\loader runner\lib\loader runner。js:364:11
位于F:\temp\playway\mobx reactjsx\node\u modules\loader runner\lib\loader runner。js:230:18
在上下文中。回调(F:\temp\playway\mobx reactjsx\node\u modules\loader runner\lib\LoaderRunner.js:111:13)
在
at过程_tickCallback(内部/进程/下一步\u tick.js:169:7)@/node\u modules/antd/lib/style/index。减去@
./node\u modules/antd/lib/button/style/index。js@/src/索引。js公司@
多(Web包)-开发服务器/客户端?
http://localhost:8080
./src/索引。js公司
中出错/node\u modules/antd/lib/button/style/index。更少的模块构建
失败:ModuleBuildError:模块生成失败:
/*stylelint禁用
声明前面有空格,没有重复的选择器*/^无法读取
未定义的属性“length”
在F:\temp\playway\mobx reactjsx\node\u modules\antd\lib\style\color\bezierEasing中。较少的
(第1行第1列)
在RunLoader上(F:\temp\playway\mobx reactjsx\node\u modules\webpack\lib\NormalModule.js:195:19)
位于F:\temp\playway\mobx reactjsx\node\u modules\loader runner\lib\loader runner。js:364:11
位于F:\temp\playway\mobx reactjsx\node\u modules\loader runner\lib\loader runner。js:230:18
在上下文中。回调(F:\temp\playway\mobx reactjsx\node\u modules\loader runner\lib\LoaderRunner.js:111:13)
在
at过程_tickCallback(内部/进程/下一步\u tick.js:169:7)@/node\u modules/antd/lib/button/style/index。减去@
./node\u modules/antd/lib/button/style/index。js@/src/索引。js公司@
多(Web包)-开发服务器/客户端?
http://localhost:8080
./src/索引。js公司
儿童提取文本网页包插件
node\u模块/提取文本网页包插件/dist
node\u模块/css加载程序/索引。js!node\u模块/less loader/dist/cjs。js??参考——1-2!node\u modules/antd/lib/style/index。减去:
[0] ./node\u模块/css加载器/node\u模块/less loader/dist/cjs。js?{“modifyVars”:{“@primary color”:“#193D71”},“root”:“F://temp//playway//mobx reactjsx”,“javascriptEnabled”:true}/node\u modules/antd/lib/style/index。较少的
302字节{0}[生成][失败][1错误]
ERROR in ./node_modules/css-loader!./node_modules/less-loader/dist/cjs.js?{"modifyVars":{"@primary-color":"#193D71"},"root":"F://temp//Playground//mobx-reactjsx","javascriptEnabled":true}!./node_modules/antd/lib/style/index.less
Module build failed:
/* stylelint-disable declaration-bang-space-before,no-duplicate-selectors */
^
Cannot read property 'length' of undefined
in F:\temp\Playground\mobx-reactjsx\node_modules\antd\lib\style\color\bezierEasing.less
(第1行,第1列)子提取文本网页包插件
node\u模块/提取文本网页包插件/dist
node\u模块/css加载程序/索引。js!node\u模块/less loader/dist/cjs。js??参考——1-2!node\u modules/antd/lib/button/style/index。减去:
[0] ./node\u模块/css加载器/node\u模块/less loader/dist/cjs。js?{“modifyVars”:{“@primary color”:“#193D71”},“root”:“F://temp//playway//mobx reactjsx”,“javascriptEnabled”:true}/node\u modules/antd/lib/button/style/index。较少的
302字节{0}[生成][失败][1错误]
ERROR in ./node_modules/css-loader!./node_modules/less-loader/dist/cjs.js?{"modifyVars":{"@primary-color":"#193D71"},"root":"F://temp//Playground//mobx-reactjsx","javascriptEnabled":true}!./node_modules/antd/lib/button/style/index.less
Module build failed:
/* stylelint-disable declaration-bang-space-before,no-duplicate-selectors */
^
Cannot read property 'length' of undefined
in F:\temp\Playground\mobx-reactjsx\node_modules\antd\lib\style\color\bezierEasing.less
(第1行,第1列)网页:未能编译。
更新1:
这是我的网页。配置。json
var path = require('path');
var webpack = require('webpack');
const fs = require('fs');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const lessToJs = require('less-vars-to-js');
const themeVariables = lessToJs(fs.readFileSync(path.join(__dirname, './scripts/ant-theme-vars.less'), 'utf8'));
module.exports = {
watch: true,
context: path.resolve(__dirname, './src'),
devtool: 'source-map',
entry: [
'./src/index.js'
],
output: {
path: path.resolve(__dirname, './dist'),
filename: '[name].bundle.js'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new ExtractTextPlugin('style.css')
],
resolve: {
extensions: ['.js', '.jsx']
},
module: {
rules: [{
test: /\.jsx?$/,
use: ['babel-loader'],
include: path.join(__dirname, 'src')
},
{
test: /\.less$/,
use: ExtractTextPlugin.extract([
{loader: "css-loader"},
{loader: "less-loader",
options: {
modifyVars: themeVariables,
root: path.resolve(__dirname, './')
}
}
])
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
use: "css-loader"
})
},]
}
};
现在,错误消息变为:
多(Web包)错误-开发服务器/客户端?
http://localhost:8080
./src/索引。未找到js模块:错误:无法解析“”/src/索引。js'
在“/用户/温斯顿/tmp/游乐场/mobx reactjsx/src”中@多
(网页包)-开发服务器/客户端?
http://localhost:8080
./src/索引。js公司
(项目结构)
我有索引。项目文件夹下的js/src
我正在尝试将Ant设计与较少的支持以及此处的按需导入功能集成在一起:
https://ant.design/docs/react/use-with-create-react-app
在高级指南部分。
在本节中,它使用react app rewired,但我的项目使用webpack 3(我的项目基于此
https://github.com/mobxjs/mobx-react-boilerplate
),因此无法在我的情况下使用rewired命令。
所以我找到了另一篇文章:
https://medium.com/@GeoffMiller/how-to-customize-ant-design-with-react-webpack-the-missing-guide-c6430f2db10f
这是我的代码:
包裹json
"start": "webpack-dev-server --hot --open",
网页包。配置。json
const fs = require('fs');
const lessToJs = require('less-vars-to-js');
const themeVariables = lessToJs(fs.readFileSync(path.join(__dirname, './scripts/ant-theme-vars.less'), 'utf8'));
....
module:{
.....
rules:[
.....
test: /\.less$/,
use: [
{loader: "style-loader"},
{loader: "css-loader"},
{loader: "less-loader",
options: {
modifyVars: themeVariables
}
}
]
]
}
指数js公司
import {Button} from 'antd';
<Button type="primary">Hi!</Button>
.巴别塔LRC
{
"presets": [
"react",
"es2015",
"stage-1"
],
"plugins": [
["import", {"libraryName": "antd", "style": true} ],
"transform-decorators-legacy"
]
}
以下是来自控制台的错误消息: