forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scripts: Use fork of
rtlcss-webpack-plugin
to fix issues with deps (W…
…ordPress#68201) * Scripts: Use fork of `rtlcss-webpack-plugin` to fix issues with dependencies * Update the changelog entry * Fix path in the moved plugin * Fix path to PhpFilePathsPlugin in webpack config Co-authored-by: gziolo <[email protected]> Co-authored-by: manzoorwanijk <[email protected]> Co-authored-by: stein2nd <[email protected]>
- Loading branch information
1 parent
500883f
commit af0e277
Showing
9 changed files
with
85 additions
and
126 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* Parts of this source were derived and modified from the package | ||
* rtlcss-webpack-plugin, released under the MIT license. | ||
* | ||
* https://github.com/wix-incubator/rtlcss-webpack-plugin | ||
* | ||
* Copyright (c) 2018 Wix.com | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
const path = require( 'node:path' ); | ||
const rtlcss = require( 'rtlcss' ); | ||
const webpack = require( 'webpack' ); | ||
|
||
const cssOnly = ( filename ) => path.extname( filename ) === '.css'; | ||
|
||
class RtlCssPlugin { | ||
processAssets = ( compilation, callback ) => { | ||
const chunks = Array.from( compilation.chunks ); | ||
|
||
// Explore each chunk (build output): | ||
chunks.forEach( ( chunk ) => { | ||
// Explore each asset filename generated by the chunk: | ||
const files = Array.from( chunk.files ); | ||
|
||
files.filter( cssOnly ).forEach( ( filename ) => { | ||
// Get the asset source for each file generated by the chunk: | ||
const src = compilation.assets[ filename ].source(); | ||
const dst = rtlcss.process( src ); | ||
const dstFileName = compilation.getPath( '[name]-rtl.css', { | ||
chunk, | ||
cssFileName: filename, | ||
} ); | ||
|
||
compilation.assets[ dstFileName ] = | ||
new webpack.sources.RawSource( dst ); | ||
chunk.files.add( dstFileName ); | ||
} ); | ||
} ); | ||
|
||
callback(); | ||
}; | ||
|
||
apply( compiler ) { | ||
compiler.hooks.compilation.tap( 'RtlCssPlugin', ( compilation ) => { | ||
compilation.hooks.processAssets.tapAsync( | ||
{ | ||
name: 'TPAStylePlugin.pluginName', | ||
stage: compilation.PROCESS_ASSETS_STAGE_OPTIMIZE, | ||
}, | ||
( chunks, callback ) => | ||
this.processAssets( compilation, callback ) | ||
); | ||
} ); | ||
} | ||
} | ||
|
||
module.exports = RtlCssPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters