Comments (15)
用的 antd-init 的脚手架么? webpack.config.js
贴出来看下。
from antd-init.
// 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.
@sorrycc 可以具体说明下版本更新后,如何能改组件库里的less的变量值呢?
from antd-init.
默认的脚手架是有效的,感觉是修改了配置和 这个变化 的冲突导致的。
from antd-init.
// 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.
@sorrycc 那段删掉就好了。
from antd-init.
去掉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.
@sorrycc @afc163 配置文件中的删掉那部分后,部分less变量可以改值,比如字体大小,行高等,有些不可以,比如主题颜色好像就改不了,请教如何解决
from antd-init.
这里例子是可以修改主色的,我测试过最新的配置,你参照一下吧。https://github.com/ant-design/antd-init/tree/c0bde69268b528de4bf137e918dc7df9f339101d/examples/customize-antd-theme#less
from antd-init.
npm@2 下会报类似楼主的错误。
from antd-init.
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.
感谢各位的帮忙!!!
from antd-init.
解决
个人推荐方法二。
方法一:
在 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.
赞~
我上面加 inline 之后就好了,原来不走 less 解析能解决路径问题。
方法三
等下个版本。
from antd-init.
@sorrycc @afc163 更新代码后,还是存在部分less变量可以改值,比如@font-size-base,@link-color等,有些不可以,比如@primary-color,@border-radius-base,@border-radius-sm好像就改不了,请教如何解决,能说明的具体点么?
from antd-init.
Related Issues (20)
- 静态数据不加载,不知道如何调试 HOT 1
- How to use webpack2 customized the antd theme and icon url. HOT 4
- antd主题切换 HOT 3
- antd主题切换后自定义的css被覆盖的问题 HOT 1
- 自定义主题后,pagination组件按钮样式异常
- theme:导入报错小细节
- theme:导入报错小细节 HOT 1
- build后报错,该如何解决
- 如果我用的脚手架不是antd-init 和 dva-cli呢?该怎么处理? HOT 1
- 如何针对不同的entry做不同的modifyVars HOT 2
- 自定义iconfont路径只能用绝对路径? HOT 2
- 如何获取Icon的style值以及动态的改变style?
- 使用 parceljs ,本地部署 Iconfont 失败
- 想问下,不想修改整个主题,只想要修改某个组件的样式应该怎么做? HOT 1
- 在antd-pro中使用图标本地化时,报错
- Invalid setting font-family HOT 1
- my theme does not change help
- Translate this example to english
- 请问如果使用package.theme来自定义iconfont的路径无效,可以参考这个解决方案。
- 提错地方了,请无视 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from antd-init.