-
Notifications
You must be signed in to change notification settings - Fork 11
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 with imports from a module? #2
Comments
Unfortunately, it can't resolve imports on the string map. What you would do is extract the styles in a CSS file and within the map point to the location of where it is located. Do mind the styles should be inside the public folder so they can be available inside the browser. You could do this using Webpack, but in my opinion, is too convoluted and would require to create a plugin just for that, also you would have to compile the styles on each change. I am going to write the solution for this on my blog post, however, since you need it now I will tell you how to. I solved this problem by using Gulp. I create Less stylesheet with imports from AntD and any variable I want to modify, which means I can create whichever theme I want, pretty scalable in my opinion. Furthermore, I use Gulp to look for every file that has Here is the Gulp code: const gulp = require('gulp')
const gulpless = require('gulp-less')
const postcss = require('gulp-postcss')
const debug = require('gulp-debug')
var csso = require('gulp-csso')
const autoprefixer = require('autoprefixer')
const NpmImportPlugin = require('less-plugin-npm-import')
gulp.task('less', function () {
const plugins = [autoprefixer()]
return gulp
.src('src/theme/antd/*-theme.less')
.pipe(debug({title: 'Less files:'}))
.pipe(
gulpless({
javascriptEnabled: true,
plugins: [new NpmImportPlugin({prefix: '~'})],
}),
)
.pipe(postcss(plugins))
.pipe(
csso({
debug: true,
}),
)
.pipe(gulp.dest('./public'))
}) I would run this script every time I update AntD, however, you could run it after any build using As said before, inside @import '~antd/lib/style/color/colorPalette.less';
@import '~antd/dist/antd.less';
@import '~antd/lib/style/themes/dark.less';
@import './default-vars-override.less';
@component-background: #303030;
@body-background: #303030;
@popover-background: #303030;
@border-color-base: #6f6c6c;
@border-color-split: #424242;
@table-header-sort-active-bg: #424242;
@card-skeleton-bg: #424242;
@skeleton-color: #424242;
@table-header-sort-active-bg: #424242; To use in your theme map you just point to your public folder. If you are using CRA do it this way: const themes = {
dark: `${process.env.PUBLIC_URL}/dark-theme.css`,
light: `${process.env.PUBLIC_URL}/light-theme.css`,
} I hope this helped. Cheers 🚀 |
@JoseRFelix can I use sass files? It would be nice if this package could support scss. |
I have the same issue. My theme files are provided as npm package, and i need to import them from node_modules not as public assets. Embedding the styles instead of using the |
Hey @JoseRFelix
I found your post at the Ant Design repository and to me this approach looks nice. Thank you for making this.
Currently I'm trying to figure how to use this while importing styles from a package, like that of Ant Design? Particularly; how will a map of strings make it possible to resolve imports and package them at build time?
The text was updated successfully, but these errors were encountered: