Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
systemjs-webpack-interop
Advanced tools
helpers for getting webpack bundles to be loaded by systemjs
The systemjs-webpack-interop package is designed to facilitate the integration of Webpack bundles with SystemJS, a dynamic module loader. This package helps in configuring Webpack to produce bundles that can be easily consumed by SystemJS, making it easier to manage dependencies and load modules dynamically in a micro-frontend architecture.
Setting Public Path
This feature allows you to set the public path dynamically based on the module name. This is particularly useful in micro-frontend architectures where different applications might be served from different locations.
const { setPublicPath } = require('systemjs-webpack-interop');
setPublicPath('my-app');
Dynamic Import Map
This feature allows you to set an import map dynamically, which SystemJS uses to resolve module paths. This is useful for managing dependencies that are hosted on different CDNs or servers.
const { setImportMap } = require('systemjs-webpack-interop');
setImportMap({
imports: {
'my-dependency': 'https://cdn.example.com/my-dependency.js'
}
});
Webpack Plugin
This feature provides a Webpack plugin that automatically sets the public path for your Webpack bundles based on the SystemJS module name. This ensures that your bundles are correctly loaded by SystemJS.
const SystemJSPublicPathWebpackPlugin = require('systemjs-webpack-interop/SystemJSPublicPathWebpackPlugin');
module.exports = {
plugins: [
new SystemJSPublicPathWebpackPlugin({
systemjsModuleName: 'my-app'
})
]
};
Single-spa is a framework for bringing together multiple JavaScript microfrontends in a frontend application. It provides a more comprehensive solution for micro-frontend architecture, including routing and lifecycle management, whereas systemjs-webpack-interop focuses specifically on the integration between Webpack and SystemJS.
Import-map-overrides is a tool that allows you to override import maps in the browser. It provides a user interface for dynamically changing import maps, which can be useful for development and debugging. While systemjs-webpack-interop helps set import maps programmatically, import-map-overrides offers a more interactive approach.
An npm package for webpack bundles that are used as systemjs modules.
systemjs-webpack-interop is an npm package that exports functions that help you create a webpack bundle that is consumable by SystemJS as an in-browser module.
Specifically, the library does two things:
Webpack has several features that are geared towards better interop with SystemJS. Here are relevant links:
libraryTarget: 'system'
on that page)SystemJS
on that page)Note that systemjs-webpack-interop requires systemjs@>=6.
npm install --save systemjs-webpack-interop
# Or
yarn add systemjs-webpack-interop
systemjs-webpack-interop will dynamically set the webpack public path based on the URL that a SystemJS module was downloaded from.
You can set the public path by adding the SystemJSPublicPathWebpackPlugin.
// webpack.config.js
const SystemJSPublicPathWebpackPlugin = require("systemjs-webpack-interop/SystemJSPublicPathWebpackPlugin");
module.exports = {
plugins: [
new SystemJSPublicPathWebpackPlugin({
// optional: defaults to 1
// If you need the webpack public path to "chop off" some of the directories in the current module's url, you can specify a "root directory level". Note that the root directory level is read from right-to-left, with `1` indicating "current directory" and `2` indicating "up one directory":
rootDirectoryLevel: 1,
// ONLY NEEDED FOR WEBPACK 1-4. Not necessary for webpack@5
systemjsModuleName: "@org-name/project-name"
})
]
};
You can also set the public path with code inside of your webpack project.
If you're using at least webpack 5.0.0-beta.15, simply add the following to the very top of your webpack entry file:
/* For a module at http://localhost:8080/dist/js/main.js,
* this will set the webpack public path to be
* http://localhost:8080/dist/js/
*/
import "systemjs-webpack-interop/auto-public-path";
If you need the webpack public path to "chop off" some of the directories in the current module's url, you can specify a "root directory level". Note that the root directory level is read from right-to-left, with 1
indicating "current directory" and 2
indicating "up one directory":
/* For a module at http://localhost:8080/dist/js/main.js,
* this will set the webpack public path to be
* http://localhost:8080/js/
*/
import "systemjs-webpack-interop/auto-public-path/2";
/* For a module at http://localhost:8080/dist/js/main.js,
* this will set the webpack public path to be
* http://localhost:8080/
*/
import "systemjs-webpack-interop/auto-public-path/3";
To set the webpack public path in older versions of webpack, add the following to the very top of your webpack entry file:
import "systemjs-webpack-interop/resource-query-public-path?systemjsModuleName=@org-name/project-name";
To set the root directory level:
import "systemjs-webpack-interop/resource-query-public-path?systemjsModuleName=@org-name/project-name&rootDirectoryLevel=2";
To set the webpack public path in older versions of webpack, you'll need to do two things:
set-public-path.js
/* In your webpack entry file, add the following import as the very very first import. It is important that it is first.
* Here's a link to learn about entry files: https://webpack.js.org/configuration/entry-context/#entry
*/
import "./set-public-path.js";
/* set-public-path.js */
import { setPublicPath } from "systemjs-webpack-interop";
/* Make sure your import map has the name of your module in it. Example:
{
"imports": {
"@org-name/my-module": "https://example.com/dist/js/main.js"
}
}
*/
// __webpack_public_path__ will be set to https://example.com/dist/js/
setPublicPath("foo");
If you need the webpack public path to "chop off" some of the directories in the current module's url, you can specify a "root directory level". Note that the root directory level is read from right-to-left, with 1
indicating "current directory" and 2
indicating "up one directory":
/* For a module at http://localhost:8080/dist/js/main.js,
* this will set the webpack public path to be
* http://localhost:8080/dist/
*/
setPublicPath("foo", 2);
setPublicPath(systemjsModuleName, rootDirectoryLevel = 1)
rootDirectoryLevel
indicates which /
character in the full url string to use as the directory,
scanning the url from right-to-left.undefined
systemjs-webpack-interop exports NodeJS functions for helping you set up and verify a webpack config so that it works well with SystemJS.
Note that these functions only work if you're using webpack@>=4.30.0. Before that version of webpack, output.libraryTarget
of "system"
did not exist.
// webpack.config.js
const systemjsInterop = require("systemjs-webpack-interop/webpack-config");
// Pass in your webpack config, and systemjs-webpack-interop will make it
// work better with SystemJS
module.exports = systemjsInterop.modifyWebpackConfig({
output: {
filename: "bundle.js"
},
module: {
rules: []
},
devtool: "sourcemap"
});
modifyWebpackConfig(config)
config
(optional): A webpack config object. If not provided, a default one will be created for you.A new, modified webpack config object.
// webpack.config.js
const systemjsInterop = require("systemjs-webpack-interop/webpack-config");
// Pass in your webpack config, and systemjs-webpack-interop will make it
// work better with SystemJS
module.exports = {
output: {
libraryTarget: "system"
},
module: {
rules: [{ parser: { system: false } }]
}
};
// Throws errors if your webpack config won't interop well with SystemJS
systemjsInterop.checkWebpackConfig(module.exports);
checkWebpackConfig(config)
config
(required): A webpack config object to be verified. If the config object isn't following best practices for interop with systemjs, and error will be thrown.undefined
if the webpack config is valid, and an Error will be thrown otherwise.
FAQs
helpers for getting webpack bundles to be loaded by systemjs
We found that systemjs-webpack-interop demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.