
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
babel-plugin-import-noop
Advanced tools
Transform certain types of `import` statements into noops that declare empty objects.
A babel plugin to turn certain types of import
statements into noops that declare empty objects.
If you're using CSS Modules via a build tool like Webpack's css-loader, then when you build your app bundle webpack will magically transform imports like:
import style from './some-style.scss';
— into JavaScript that injects this style into your pages.
However, if you want to run tests, you'll hit a syntax error if you try to run the JavaScript files as-is, since the CSS they're importing isn't valid JavaScript. You could compile an entire "test bundle" with webpack before running the tests, but that adds a substantial boot time to every run. Instead, you can use the babel require hook, and use this plugin to replace all instances of:
import style from './some-style.scss';
with
const style = {};
— during compilation.
$ npm install --save-dev babel-plugin-import-noop
Then, in your .babelrc:
{
"plugins": ["import-noop"]
}
Or, to only load this plugin during tests (i.e. not in your actual bundle):
{
"env": {
"test": {
"plugins": ["import-noop"]
}
}
}
NODE_ENV=test mocha ....
To specify a list of file extensions which should be transformed, you can add additional options to the plugin declaration:
{
"plugins": [
["import-noop", {
"extensions": ["scss", "css"]
}]
]
}
Since the newly defined object won't have any properties, anything you're
reading from it in your code (e.g. style.className) will resolve to
undefined. A pull request to allow defining properties using the plugin
configuration would be very useful!
MIT
FAQs
Transform certain types of `import` statements into noops that declare empty objects.
We found that babel-plugin-import-noop demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.