Coder Social home page Coder Social logo

Comments (15)

sorrycc avatar sorrycc commented on June 15, 2024

用的 antd-init 的脚手架么? webpack.config.js 贴出来看下。

from antd-init.

liujhfly avatar liujhfly commented on June 15, 2024
// Learn more on how to config.
// - https://github.com/ant-tool/atool-build#配置扩展

const webpack = require('atool-build/lib/webpack');
const fs = require('fs');
const path = require('path');
const glob = require('glob');

module.exports = function (webpackConfig) {
  webpackConfig.babel.plugins.push('transform-runtime');
  webpackConfig.babel.plugins.push(['antd', {
    style: 'css',  // if true, use less
  }]);

  // Enable this if you have to support IE8.
  // webpackConfig.module.loaders.unshift({
  //   test: /\.jsx?$/,
  //   loader: 'es3ify-loader',
  // });

  // Parse all less files as css module.
  webpackConfig.module.loaders.forEach(function(loader, index) {
    if (typeof loader.test === 'function' && loader.test.toString().indexOf('\\.less$') > -1) {
      loader.test = /\.dont\.exist\.file/;
    }
    if (loader.test.toString() === '/\\.module\\.less$/') {
      loader.test = /\.less$/;
    }
  });

  // Load src/entries/*.js as entry automatically.
  const files = glob.sync('./src/entries/*.js');
  const newEntries = files.reduce(function(memo, file) {
    const name = path.basename(file, '.js');
    memo[name] = file;
    return memo;
  }, {});
  webpackConfig.entry = Object.assign({}, webpackConfig.entry, newEntries);

  return webpackConfig;
};

from antd-init.

liujhfly avatar liujhfly commented on June 15, 2024

@sorrycc 可以具体说明下版本更新后,如何能改组件库里的less的变量值呢?

from antd-init.

afc163 avatar afc163 commented on June 15, 2024

默认的脚手架是有效的,感觉是修改了配置和 这个变化 的冲突导致的。

from antd-init.

sorrycc avatar sorrycc commented on June 15, 2024
  // Parse all less files as css module.
  webpackConfig.module.loaders.forEach(function(loader, index) {
    if (typeof loader.test === 'function' && loader.test.toString().indexOf('\\.less$') > -1) {
      loader.test = /\.dont\.exist\.file/;
    }
    if (loader.test.toString() === '/\\.module\\.less$/') {
      loader.test = /\.less$/;
    }
  });

这段删掉试试。

from antd-init.

afc163 avatar afc163 commented on June 15, 2024

@sorrycc 那段删掉就好了。

from antd-init.

maoyongming avatar maoyongming commented on June 15, 2024

去掉webpackConfig那段代码,打包不报错了,但是修改的theme样式不生效,1.1.0版本可以;1.1.1和1.1.2都不行;引用第3种办法
@import "~antd/lib/style/themes/default.less";
@import "your-theme-file"; // 变量文件
@import "~antd/lib/style/core/index.less";
@import "~antd/lib/style/components.less";

from antd-init.

liujhfly avatar liujhfly commented on June 15, 2024

@sorrycc @afc163 配置文件中的删掉那部分后,部分less变量可以改值,比如字体大小,行高等,有些不可以,比如主题颜色好像就改不了,请教如何解决

from antd-init.

afc163 avatar afc163 commented on June 15, 2024

这里例子是可以修改主色的,我测试过最新的配置,你参照一下吧。https://github.com/ant-design/antd-init/tree/c0bde69268b528de4bf137e918dc7df9f339101d/examples/customize-antd-theme#less

from antd-init.

afc163 avatar afc163 commented on June 15, 2024

npm@2 下会报类似楼主的错误。

from antd-init.

afc163 avatar afc163 commented on June 15, 2024
ERROR in ./index.less
Module build failed: ModuleNotFoundError: Module not found: Error: Cannot resolve module 'normalize.css/normalize.css' in /Users/afc163/Projects/antd-init/examples/customize-antd-theme
    at /Users/afc163/Projects/antd-init/examples/customize-antd-theme/node_modules/atool-build/node_modules/webpack/lib/Compilation.js:229:38
    at onDoneResolving (/Users/afc163/Projects/antd-init/examples/customize-antd-theme/node_modules/atool-build/node_modules/webpack/lib/NormalModuleFactory.js:29:20)
    at /Users/afc163/Projects/antd-init/examples/customize-antd-theme/node_modules/atool-build/node_modules/webpack/lib/NormalModuleFactory.js:85:20
    at /Users/afc163/Projects/antd-init/examples/customize-antd-theme/node_modules/atool-build/node_modules/webpack/node_modules/async/lib/async.js:726:13
    at /Users/afc163/Projects/antd-init/examples/customize-antd-theme/node_modules/atool-build/node_modules/webpack/node_modules/async/lib/async.js:52:16
    at done (/Users/afc163/Projects/antd-init/examples/customize-antd-theme/node_modules/atool-build/node_modules/webpack/node_modules/async/lib/async.js:241:17)
    at /Users/afc163/Projects/antd-init/examples/customize-antd-theme/node_modules/atool-build/node_modules/webpack/node_modules/async/lib/async.js:44:16
    at /Users/afc163/Projects/antd-init/examples/customize-antd-theme/node_modules/atool-build/node_modules/webpack/node_modules/async/lib/async.js:723:17
    at /Users/afc163/Projects/antd-init/examples/customize-antd-theme/node_modules/atool-build/node_modules/webpack/node_modules/async/lib/async.js:167:37
    at /Users/afc163/Projects/antd-init/examples/customize-antd-theme/node_modules/atool-build/node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:24:19
 @ ./index.jsx 23:0-23

from antd-init.

liujhfly avatar liujhfly commented on June 15, 2024

感谢各位的帮忙!!!

from antd-init.

sorrycc avatar sorrycc commented on June 15, 2024

解决

个人推荐方法二。

方法一:

webpack.config.js 里加入 fallback 的配置。

const fallback = webpackConfig.resolve.fallback || [];
webpackConfig.resolve.fallback = fallback.concat(path.join(__dirname, 'node_modules/antd/node_modules'));

方法二:

项目安装 normalize.css 依赖,npm i normalize.css --save

原因

antd 的 less 文件走了 less-loader 之后,会被合并到项目的 less 编译结果里,这之后就不会再基于 node_modules/antd 的目录做模块解析了。

from antd-init.

afc163 avatar afc163 commented on June 15, 2024

赞~

我上面加 inline 之后就好了,原来不走 less 解析能解决路径问题。

方法三

等下个版本。

from antd-init.

liujhfly avatar liujhfly commented on June 15, 2024

@sorrycc @afc163 更新代码后,还是存在部分less变量可以改值,比如@font-size-base,@link-color等,有些不可以,比如@primary-color,@border-radius-base,@border-radius-sm好像就改不了,请教如何解决,能说明的具体点么?

from antd-init.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.