首页 新闻 赞助 找找看

基于webpack的react脚手架 更改antd主题问题

0
[已关闭问题] 关闭于 2018-11-26 20:36

在webpack.config.dev.js中的babel-loader的options配置如下
"plugins": [
["import", { libraryName: "antd-mobile", style: "css" }]
],
问题一:预加载无效。不报错,就是测试的Button没有样式

尝试更改antd主题颜色:
1.在webpack.config.dev.js中的babel-loader的options配置如下
把上面的style改成了true

2.在 package.json 文件中添加一个 theme 字段,里面将包含所有我们想要修改的主题样式

"theme": {
"brand-primary": "red",
"color-text-base": "#333",
}
3.在webpack.config.dev.js中添加

const theme = require('./package.json').theme;

module.exports = {

  module: {
  
      rules: [
       
          {
              test: /\.css$/,
              use: [
                  'style-loader',
                  'css-loader',
              ],
          },
          {
              test: /\.less$/,
              use: [
                  'style-loader',
                  'css-loader',
                  {loader: 'less-loader', options: {modifyVars: theme}},
              ],
              include: /node_modules/,
          },
      
      ],
  },
  

}

问题二:运行后就报错了。提示的是
npm ERR! file F:\react\019尚硅谷-React项目-硅谷直聘\源码\test\package.json
npm ERR! code EJSONPARSE
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected token } in JSON at position 3390 while parsing near '...ext-base": "#333",
npm ERR! JSON.parse },
npm ERR! JSON.parse }
npm ERR! JSON.parse '
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Program Files\nodejs\node_cache_logs\2018-11-24T16_01_12_875Z-debug.log

求大佬帮忙 困扰我两天了 不知道如何解决了。json文件是没错的。没有语法错误,less也是2.7.3版本。

霸森的主页 霸森 | 菜鸟二级 | 园豆:202
提问于:2018-11-25 00:21
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册