-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Scripts: Control Directives for RTLCSS don't work in build
command
#68364
Comments
build
commandbuild
command
I can confirm that the issue is present, sharing the screencast for the same: |
@t-hamano @Rishit30G when looking at start.js and build.js the problem seems to come from: process.env.NODE_ENV = process.env.NODE_ENV || 'production'; which is in the build.js but not the start.js. When your SCSS code is processed in production mode, the comments are optimized out before RTLCSS gets the file for processing. So to fix this, comments need to be kept in for production mode and then removed only after RTLCSS runs. |
Changing this from: options: {
sourceMap: ! isProduction,
} to: options: {
sourceMap: ! isProduction,
sassOptions: {
style: 'expanded'
}
} will fix it and make control directives work with production builds. The only issue is that the outputted CSS won't be minified anymore. So something needs to run after SCSS compilation and RTLCSS processing to remove comments and minify the CSS files once again. |
@t-hamano @Rishit30G I found a solution! Instead of doing: /*rtl:ignore*/ Do: /*!rtl:ignore*/ The /*! */ Instead of this one: /* */ This issue can be closed now. |
@SmushyTaco Thanks for investigating.
It may indeed work, but it seems like a temporary workaround. Ideally, all control directives would work as expected and all comments should be removed from the built files. So I'm leaving this issue open. |
@t-hamano it's not an issue though, it all works as intended. RTLCSS processes CSS files not any CSS preprocessors like SCSS, so the RLTCSS documentation is written accordingly. If the documentation was written for SCSS it would say what I'm saying. SCSS very clearly defines what you need to do to keep comments in for compilation in a production environment, we just weren't aware of the proper way of using it with SCSS. |
Thanks for sharing the solution @SmushyTaco, but unfortunately it did not work for me, maybe you can check once Screen.Recording.2025-01-02.at.10.41.57.AM.mov |
That's odd, I tested it on my PC and it worked for me. I'll investigate more later and possibly open a PR for RTLCSS if needed. |
@Rishit30G from this code, the match passes with the This is the input I've used to test: .wp-block-create-block-my-block {
/*!rtl:ignore*/
text-align: left;
/*!rtl:remove*/
background: #CCC;
} When I build with:
the index.css file is: .wp-block-create-block-my-block{/*!rtl:ignore*/text-align:left;/*!rtl:remove*/background:#ccc} and the index-rtl.css file is: .wp-block-create-block-my-block{text-align:left} But when I build with:
the index.css file is: .wp-block-create-block-my-block{background:#ccc;text-align:left} and the index-rtl.css file is: .wp-block-create-block-my-block{background:#ccc;text-align:right} The issue is the usage of index.css .wp-block-create-block-my-block{background:#ccc;text-align:left/*!rtl:remove*//*!rtl:ignore*/} index-rtl.css: .wp-block-create-block-my-block{background:#ccc;text-align:right/*!rtl:remove*//*!rtl:ignore*/} And when I completely remove it, it works as intended. So to summarize, when using with RTLCSS control directives with SCSS you need to use this comment format: /*! */ and the usage of |
Okay I've found a solution. Changing this from: preset: [
'default',
{
discardComments: {
removeAll: true,
},
},
], to: preset: [
'default',
{
discardComments: {
remove(comment) {
return !/^\s*!?\s*rtl:/.test(comment);
},
},
cssDeclarationSorter: false
},
], Fixes everything. I'll open a PR to fix and close this issue. |
This solves WordPress#68364 to allow for the proper use of control directives.
@t-hamano, thank you for the report. It looks like it never fully worked with the More realistic alternative would be to move gutenberg/packages/scripts/plugins/rtlcss-webpack-plugin/index.js Lines 34 to 46 in 382af64
|
Great to hear you plan to maintain the I don't think it matters in this case whether the WordPress project uses its copy of the webpack plugin or not. In fact, if you plan to maintain a fork of |
Description
In #61540, wp-scripts supported CSS for RTL languages. Also, with RTLCSS, you can add some processing via the Control Directives.
However, this Control Directives does not seem to work with the
build
command.I thought that #68201 might be affecting this, but it seems that's not the case. I don't know if the control directives were not working from the beginning.
cc @gziolo @ryelle
Step-by-step reproduction instructions
Use the following command to create a block without wp-script:
Update the
my-block/src/editor.scss
file as follows:✅ Run
../node_modules/.bin/wp-scripts start
and check the build file. Confirm that the controls directive is working.index.css
:index-rtl.css
:❌ Run
../node_modules/.bin/wp-scripts build
and check the build file. Confirm that the controls directive is NOT working.index.css
:index-rtl.css
:Screenshots, screen recording, code snippet
b57b77409fdef37f9e0aea1bd2260107.mp4
Environment info
OS: WSL2 (Ubuntu 22.04.4 LTS)
Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Please confirm which theme type you used for testing.
The text was updated successfully, but these errors were encountered: