Skip to content

Commit

Permalink
Reduce the amount of comments in compiled CSS and bundled CSS-in-JS
Browse files Browse the repository at this point in the history
Signed-off-by: Miki <[email protected]>
  • Loading branch information
AMoo-Miki committed Aug 1, 2023
1 parent a52e95c commit c5ed484
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 2 deletions.
7 changes: 7 additions & 0 deletions packages/osd-optimizer/src/worker/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ export function getWebpackConfig(bundle: Bundle, bundleRefs: BundleRefs, worker:
sourceMap: !worker.dist,
},
},
{
loader: 'comment-stripper',
options: {
language: 'css',
},
},
],
},
{
Expand Down Expand Up @@ -164,6 +170,7 @@ export function getWebpackConfig(bundle: Bundle, bundleRefs: BundleRefs, worker:
},
},
},
'comment-stripper',
{
loader: 'sass-loader',
options: {
Expand Down
3 changes: 2 additions & 1 deletion packages/osd-ui-framework/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* under the License.
*/

const { strip } = require('comment-stripper');
const sass = require('node-sass');
const postcss = require('postcss');
const postcssConfig = require('@osd/optimizer/postcss.config.js');
Expand Down Expand Up @@ -91,7 +92,7 @@ module.exports = function (grunt) {
}

postcss([postcssConfig])
.process(result.css, { from: src, to: dest })
.process(strip(result.css.toString('utf8')), { from: src, to: dest })
.then((result) => {
grunt.file.write(dest, result.css);

Expand Down
1 change: 1 addition & 0 deletions packages/osd-ui-framework/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@elastic/eui": "npm:@opensearch-project/[email protected]",
"@osd/babel-preset": "1.0.0",
"@osd/optimizer": "1.0.0",
"comment-stripper": "^0.0.1",
"grunt": "^1.5.2",
"grunt-babel": "^8.0.0",
"grunt-contrib-clean": "^2.0.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/osd-ui-shared-deps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"abortcontroller-polyfill": "^1.4.0",
"angular": "^1.8.2",
"axios": "^0.27.2",
"comment-stripper": "^0.0.1",
"compression-webpack-plugin": "npm:@amoo-miki/[email protected]",
"core-js": "^3.6.5",
"custom-event-polyfill": "^0.3.0",
Expand All @@ -42,6 +43,8 @@
"@osd/babel-preset": "1.0.0",
"@osd/dev-utils": "1.0.0",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"node-sass": "^8.0.0",
"sass-loader": "^10.4.1",
"css-loader": "^5.2.7",
"del": "^6.1.1",
"loader-utils": "^2.0.4",
Expand Down
15 changes: 14 additions & 1 deletion packages/osd-ui-shared-deps/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,20 @@ exports.getWebpackConfig = ({ dev = false } = {}) => ({
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
use: [
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'comment-stripper',
options: {
language: 'css',
},
},
],
},
{
test: /\.scss$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'comment-stripper', 'sass-loader'],
},
{
include: [require.resolve('./theme.ts')],
Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6100,6 +6100,13 @@ commander@^5.0.0:
resolved "https://registry.yarnpkg.com/commander/-/commander-5.1.0.tgz#46abbd1652f8e059bddaef99bbdcb2ad9cf179ae"
integrity sha512-P0CysNDQ7rtVw4QIQtm+MRxV66vKFSvlsQvGYXZWR3qFU0jlMKHZZZgw8e+8DSah4UDKMqnknRDQz+xuQXQ/Zg==

comment-stripper@^0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/comment-stripper/-/comment-stripper-0.0.1.tgz#01759a158df1de081593fa5a2faf22ed7ac410c5"
integrity sha512-7oPLIr3U7tamLi6x2lsxBpyBqHNdEn1fNkz31FBC9nLQl348Gb/3TCdsPDjRGa99oulmGwIZsx5ArxxVvlizWA==
dependencies:
loader-utils "^2.0.0"

commondir@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
Expand Down

0 comments on commit c5ed484

Please sign in to comment.