-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use antd-mobile with babel-plugin-import in this project #1464
Comments
i have the same issue.in Layout.js, import antdStyle from 'antd-mobile/dist/antd-mobile.less'; and export default withStyles(antdStyle,s)(Layout); |
This might help you |
Here's how to modify the latest revision of Importing CSS const config = {
{stuff ...}
module: {
{stuff ...}
rules: [
{stuff ...}
// Load antd here
{
test: /\.css$/,
include: [/node_modules\/.*antd/],
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
},
{
loader: 'postcss-loader',
options: {
config: {
path: './tools/postcss.config.js',
},
},
},
],
},
// Rules for Style Sheets
{
test: reStyle,
exclude: [/node_modules\/.*antd/], // Don't load antd here!
rules: [
{stuff ...}
],
{a bunch of stuff ...}
// Only use babel-plugin-import in client side
clientConfig.module.rules[0].options.plugins = [...clientConfig.module.rules[0].options.plugins];
clientConfig.module.rules[0].options.plugins.push(['import', { libraryName: 'antd', style: 'css' }]);
export default [clientConfig, serverConfig]; Importing LESS with theme support import lessToJS from 'less-vars-to-js';
import fs from 'fs';
// Where your theme.less file lives
const themeVariables = lessToJS(fs.readFileSync(path.resolve(__dirname, '../src/components/antTheme.less'), 'utf8'));
const config = {
{stuff ...}
module: {
{stuff ...}
rules: [
{stuff ...}
// Load antd here
{
test: /\.less$/,
include: [/node_modules\/.*antd/],
use: [
{
loader: "style-loader" // creates style nodes from JS strings
}, {
loader: "css-loader" // translates CSS into CommonJS
}, {
loader: "less-loader", // compiles Less to CSS
options: {
modifyVars: themeVariables,
}
}
],
},
// Rules for Style Sheets
{
test: reStyle,
exclude: [/node_modules\/.*antd/], // Don't load antd here!
rules: [
{stuff ...}
],
{a bunch of stuff ...}
// Only use babel-plugin-import in client side
clientConfig.module.rules[0].options.plugins = [...clientConfig.module.rules[0].options.plugins];
clientConfig.module.rules[0].options.plugins.push(['import', { libraryName: 'antd', style: true }]);
export default [clientConfig, serverConfig]; |
ERROR in ./node_modules/css-loader??ref--6-rules-1!./node_modules/postcss-loader/lib??ref--6-rules-3!./node_modules/antd/lib/style/index.less ERROR in ./node_modules/css-loader??ref--6-rules-1!./node_modules/postcss-loader/lib??ref--6-rules-3!./node_modules/antd/lib/button/style/index.less (7:1) Unknown word 5 | @btn-prefix-cls: ~"@{ant-prefix}-btn";
@ ./node_modules/antd/lib/button/style/index.less 2:18-147 19:6-27:8 19:146-27:7 20:18-147 |
@tim-soft 按上面配置报错了。。。 |
@kolf in English please |
You need to exclude the ant-design dir from the default load, then include the ant-design lib in your own loader chain.
// Rules for Ant-Design
{
test: /\.less$/,
include: [
/[\\/]node_modules[\\/].*antd/,
resolvePath(SRC_DIR, 'components/antTheme.less'),
],
use: [
MiniCssExtractPlugin.loader,
//'style-loader',
{
loader: 'css-loader',
options: {
sourceMap: isDebug,
minimize: isDebug ? false : minimizeCssOptions,
},
},
{
loader: 'postcss-loader',
options: {
config: {
path: './tools/postcss.config.js',
},
},
},
{
loader: "less-loader",
options: {
modifyVars: antThemeVars,
javascriptEnabled: true
}
}
]
},
// Rules for Style Sheets
{
test: reStyle,
exclude: [
/[\\/]node_modules[\\/].*antd/,
resolvePath(SRC_DIR, 'components/antTheme.less'),
],
rules: [
// Convert CSS into JS module
{
issuer: { not: [reStyle] },
use: 'isomorphic-style-loader',
},
// Process external/third-party styles
{
exclude: SRC_DIR,
loader: 'css-loader',
options: {
sourceMap: isDebug,
minimize: isDebug ? false : minimizeCssOptions,
},
},
// Process internal/project styles (from src folder)
{
include: SRC_DIR,
loader: 'css-loader',
options: {
// CSS Loader https://github.com/webpack/css-loader
importLoaders: 1,
sourceMap: isDebug,
// CSS Modules https://github.com/css-modules/css-modules
modules: true,
localIdentName: isDebug
? '[name]-[local]-[hash:base64:5]'
: '[hash:base64:5]',
// CSS Nano http://cssnano.co/
minimize: isDebug ? false : minimizeCssOptions,
},
},
// Apply PostCSS plugins including autoprefixer
{
loader: 'postcss-loader',
options: {
config: {
path: './tools/postcss.config.js',
},
},
},
// Compile Less to CSS
// https://github.com/webpack-contrib/less-loader
// Install dependencies before uncommenting: yarn add --dev less-loader less
// {
// test: /\.less$/,
// loader: 'less-loader',
// },
// Compile Sass to CSS
// https://github.com/webpack-contrib/sass-loader
// Install dependencies before uncommenting: yarn add --dev sass-loader node-sass
// {
// test: /\.(scss|sass)$/,
// loader: 'sass-loader',
// },
],
},
clientConfig.module.rules[0].options.plugins = [
...clientConfig.module.rules[0].options.plugins,
['import', { libraryName: 'antd', style: true }],
]; |
@hyden-tan thank you very much for crating this issue! Unfortunately, we have close it due to inactivity. Feel free to re-open it or join our Discord channel for discussion. NOTE: The |
I want to add antd-mobile to featrue/redux, and use babel-plugin-import, in my webpack-config.js:
but it does not work.
The text was updated successfully, but these errors were encountered: