Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

esbuild-css-modules-plugin

Package Overview
Dependencies
Maintainers
1
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esbuild-css-modules-plugin - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

test/components/hello.world.jsx

36

index.js

@@ -12,2 +12,3 @@ const path = require('path');

const ensureDir = util.promisify(fs.ensureDir);
const pluginNamespace = 'esbuild-css-modules-plugin-namespace'

@@ -49,7 +50,9 @@ const buildCssModulesJS = async (cssFullPath, options) => {

const tmpDirPath = tmp.dirSync().name;
const { outdir, bundle } = build.initialOptions;
build.onResolve(
{ filter: /\.modules?\.(css)$/ },
{ filter: /\.modules?\.css$/, namespace: 'file' },
async (args) => {
const sourceFullPath = path.resolve(args.resolveDir, args.path);
const sourceExt = path.extname(sourceFullPath);

@@ -68,7 +71,38 @@ const sourceBaseName = path.basename(sourceFullPath, sourceExt);

if (outdir && !bundle) {
fs.ensureDirSync(outdir);
const target = path.resolve(outdir, `${path.relative(rootDir, sourceFullPath)}.js`);
fs.ensureDirSync(path.dirname(target));
fs.copyFileSync(`${tmpFilePath}.js`, target);
console.log('[esbuild-css-modules-plugin]', path.relative(rootDir, sourceFullPath), '=>', path.relative(rootDir, target))
}
if (!bundle) {
return { path: sourceFullPath, namespace: 'file' };
}
return {
path: `${tmpFilePath}.js`,
namespace: pluginNamespace,
pluginData: {
content: jsContent,
resolveArgs: {
path: args.path,
importer: args.importer,
namespace: args.namespace,
resolveDir: args.resolveDir,
kind: args.kind
}
}
};
}
);
build.onLoad({ filter: /\.modules?\.css\.js$/, namespace: pluginNamespace }, (args) => {
const {path: resolvePath, importer} = args.pluginData.resolveArgs;
const importerName = path.basename(importer);
console.log('[esbuild-css-modules-plugin]', `${resolvePath} => ${resolvePath}.js => ${importerName}`);
return { contents: args.pluginData.content, loader: 'js' };
});
}

@@ -75,0 +109,0 @@ };

4

package.json
{
"name": "esbuild-css-modules-plugin",
"version": "1.0.2",
"version": "1.0.3",
"description": "A esbuild plugin to bundle css modules into js(x)/ts(x).",

@@ -18,3 +18,3 @@ "main": "index.js",

"devDependencies": {
"esbuild": "^0.8.55"
"esbuild": "^0.11.19"
},

@@ -21,0 +21,0 @@ "dependencies": {

@@ -7,3 +7,3 @@ # esbuild-css-modules-plugin

See `./test/test.js` for examples.
See [`./test/test.js`](https://github.com/indooorsman/esbuild-css-modules-plugin/blob/master/test/test.js) for examples.

@@ -10,0 +10,0 @@ ## Install

import React from 'react';
import ReactDom from 'react-dom';
import { HelloWorld } from './hello.world';
import { HelloWorld } from './components/hello.world';

@@ -6,0 +6,0 @@ const App = () => {

@@ -18,3 +18,4 @@ const esbuild = require('esbuild');

cssModulesPlugin()
]
],
logLevel: 'info'
}).then((result) => {

@@ -25,3 +26,3 @@ console.log('[test][esbuild:bundle] done, please check `test/dist/bundle`');

esbuild.build({
entryPoints: ['app.modules.css', 'app.jsx', 'hello.world.jsx'],
entryPoints: ['./styles/app.modules.css', 'app.jsx', './components/hello.world.jsx'],
format: 'esm',

@@ -36,5 +37,6 @@ target: ['es2020'],

cssModulesPlugin()
]
],
logLevel: 'info'
}).then((result) => {
console.log('[test][esbuild:no-bundle] done, please check `test/dist/no-bundle`');
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc