
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
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 44 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
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.