Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
esbuild-ssr-css-modules-plugin
Advanced tools
esbuild plugin for bundling CSS module files for client-side and server-side logic
This esbuild Plugin bundles CSS module files for Server-Side Rendering (SSR) use cases.
Using import directives such as the following in your React components:
import styles from './Panel.module.css';
Results in exceptions when trying to render your React components on the server-side, since these will be executed in Node.js and Node.js cannot load the .css
files. (Note: if you absolutely require this, such as for local testing, have a look at node-css-require
.)
This plugin will:
(1) Install this plugin as a dependency for your project:
npm i esbuild-ssr-css-modules-plugin
# -- or
yarn add esbuild-ssr-css-modules-plugin
(2) Add this plugin to the list of plugins supplied to esbuild:
import cssPlugin from 'esbuild-ssr-css-modules-plugin';
const res = await build({
plugins: [cssPlugin()],
});
The plugin accepts the parameter onCSSGenerated
. This parameter accepts a callback function that receives one argument css
that contains snippets of CSS generated.
import cssPlugin from 'esbuild-ssr-css-modules-plugin';
const generatedCss: string[] = [];
const res = await build({
plugins: [
cssPlugin({
onCSSGenerated: (css) => {
generatedCss.push(css);
},
}),
],
});
console.log(generatedCss.join('\n'));
This can be useful for creating a CSS bundle that can be shipped with the other files packaged for the server. When generating a client-side bundle using esbuild-css-modules-client-plugin
, the option excludeCSSInject
can then be set to true for a better page load experience (no flicker of the page once CSS is injected).
The plugin supports the option jsCSSInject
. This defaults to false
. When set to true
, <script>
tags are injected to be run during script load.
import cssPlugin from 'esbuild-ssr-css-modules-plugin';
const res = await build({
plugins: [
cssPlugin({
jsCSSInject: true,
}),
],
});
This plugin will transform .css
files into JavaScript source files that contain:
Thus, when server-side rendering is performed, class names can be resolved to the transformed counter-parts and the HTML rendered with the correct class names.
This plugin will transform .css
files into JavaScript source files that contain:
<script>
tag when the script is loaded that contains the CSS (with transformed class names as per CSS module specification)Thus, when the client-side bundle is loaded, all required CSS will be injected into the page and we can use the styles
object to resolve original class names to the transformed ones.
node-css-require
: Library used for CSS module transformationFAQs
esbuild plugin for bundling CSS module files for client-side and server-side logic
The npm package esbuild-ssr-css-modules-plugin receives a total of 121 weekly downloads. As such, esbuild-ssr-css-modules-plugin popularity was classified as not popular.
We found that esbuild-ssr-css-modules-plugin demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.