
Security News
Rspack Introduces Rslint, a TypeScript-First Linter Written in Go
Rspack launches Rslint, a fast TypeScript-first linter built on typescript-go, joining in on the trend of toolchains creating their own linters.
@ima/cli-plugin-scramble-css
Advanced tools
Plugin for @ima/cli that implements CSS class minimizer and uglifier that can be reverse-compiled at runtime.
Implements CSS class minimizer and uglifier that can be reverse-compiled at runtime (you can access classes using their original name).
It works by processing all CSS files using custom PostCSS plugin, that mangles (scrambles) and minimizes all classes, while also building translation table (hashtable.json
) along the way.
The result is CSS file with mangled class names and companion hashtable that we use in our custom $CssClasses
processor to, translate existing classes used out components to the new scrambled ones.
For this feature to work you need to wrap all your classNames
in cssClasses
function. Otherwise you'll end up with scrambled classes in CSS file but original class names in your components.
import { useComponent } from '@ima/react-page-renderer';
export default function Card() {
const { cssClasses } = useComponent();
return (
// highlight-next-line
<div className={cssClasses('card')} />
);
}
or in case of class components:
import { AbstractPureComponent } from '@ima/react-page-renderer';
export default class Card extends AbstractPureComponent {
render() {
return (
// highlight-next-line
<div className={this.cssClasses('card')} />
);
}
}
npm install @ima/cli-plugin-scramble-css -D
// ./ima.config.js
const { ScrambleCssPlugin } = require('@ima/cli-plugin-scramble-css');
/**
* @type import('@ima/cli').ImaConfig
*/
module.exports = {
plugins: [new ScrambleCssPlugin()],
};
$CssClasses
override and hashtable.json
We have to provide our custom $CssClasses
processor and pass it our generate hashtable.json
file. To do that, we're going to load it's contents in the app environment:
// ./server/config/environment.js
const fs = require('fs');
const path = require('path');
const hashTablePath = path.resolve(
__dirname,
'../../build/static/css/hashTable.json'
);
module.exports = (() => {
return {
prod: {
$App: {
scrambleCss: {
hashTable: fs.existsSync(hashTablePath)
? JSON.parse(fs.readFileSync(hashTablePath))
: null,
},
},
// ...
}
}
});
Finally, the hashtable is now available under config.$App.scrambleCss.hashTable
, so we're going to provide it to the plugin's custom $CssClasses
processor in the app bind.js
file, and we're done:
// ./app/config/bind.js
import { scrambleCssClasses } from '@ima/cli-plugin-scramble-css/scrambleCssClasses';
export default (ns, oc, config) => {
oc.bind(
'$CssClasses',
scrambleCssClasses(config?.$App?.scrambleCss?.hashTable),
[]
);
};
boolean
The scrambling is enabled by default for production
environment. However you can explicitly enable/disable it using this CLI argument. This applies for both CLI commands.
new ScrambleCssPlugin(options: {
scrambleCssMinimizerOptions?: {
assetFilter?: (filename: string) => boolean;
hashTableFilename?: string;
mainAssetFilter?: (filename: string) => boolean;
};
});
object
These are passed directly into the ScrambleCssMinimizer
. You can define custom:
assetFilter
- filter files to scramble.hashTableFilename
- custom translation hashtable.json
filename. Defaults to: ./build/static/css/hashTable.json.mainAssetFilter
- should resolve to the main css file. The minimizer first processes the main.css file and generates the hashtable.json
translation table. If you then want to process other assets with existing hashtable, these should be filtered out in this function, since the minimizer minimizes them in second pass using existing hashtable.json
.Note: You should be fine with the default options in almost any situation except some special use cases.
For more information, take a look at the IMA.js documentation.
FAQs
Plugin for @ima/cli that implements CSS class minimizer and uglifier that can be reverse-compiled at runtime.
The npm package @ima/cli-plugin-scramble-css receives a total of 0 weekly downloads. As such, @ima/cli-plugin-scramble-css popularity was classified as not popular.
We found that @ima/cli-plugin-scramble-css demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 9 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Rspack launches Rslint, a fast TypeScript-first linter built on typescript-go, joining in on the trend of toolchains creating their own linters.
Security News
Hacker Demonstrates How Easy It Is To Steal Data From Popular Password Managers
Security News
Oxlint’s new preview brings type-aware linting powered by typescript-go, combining advanced TypeScript rules with native-speed performance.