Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
systemjs-hot-reloader-ex
Advanced tools
SystemJS / JSPM hot reloader with support of CSS, SCSS, SASS, LESS, Stylus, React and JavaScript
Universal hot reloader for SystemJS / JSPM.
This is more powerfull alternative to capaj/systemjs-hot-reloader
.
bs-systemjs-hot-reloader
package
which will be responsible for
SystemJS.trace
npm install browser-sync bs-systemjs-hot-reloader --save-dev
jspm install npm:systemjs-hot-reloader-ex --dev
Please refer to bs-systemjs-hot-reloader
usage to setup BrowserSync with plugin.
It is peer dependency for bs-systemjs-hot-reloader
, but tehnically could be used
as client side reloader for any 3rd party development server.
Log level could be changed on the fly with:
// Log level: 0 - none, 1 - error, 2 - info (default), 3 - debug
SystemJS.import('systemjs-hot-reloader-ex')
.then(function (exports) {
exports.default.logLevel = 3;
});
or via jspm.config.js
:
SystemJS.config({
hotReloaderOptions: {
logLevel: 3
}
});
This reloader could reload any JS module and will track all dependencies.
By default this reloader will recursively all parents of modified module and will reinject all modules.
Modules with side effects should export __unload()
hook.
Modules with alternative reload logic should export __reload()
hook.
Both hooks have array of reinjected modules as first argument.
This reloader could reload any module, including CSS, LESS, SCSS, SASS, Stylus, PostCSS if css plugin supports correct reinjection.
Server side bs-systemjs-hot-reloader
could track LESS, SCSS, SASS, Stylus
dependency tree to reload root module if one of dependencies is changed.
Avoid using of loaders via !
because in that case there is no 100% way to
convert file name into module name so reloader will have to iterate over all
registered modules to find correct module name. It is recommended to define
loader via meta
SystemJS config section for files based on their extension.
The fastest reload is guaranteed when css filename could be 1:1 resolved to module name. It works when you have css loading workflow like below:
SystemJS.config({
meta: {
"*.css": { "loader": "plugin-css" },
"*.scss": { "loader": "plugin-sass" },
"*.sass": { "loader": "plugin-sass" },
"*.less": { "loader": "plugin-less" }
},
});
import 'app.css';
import 'component.scss';
A slightly slower loading workflow (guess loader by adding !
to filename in resolver):
import 'app.css!';
import 'component.scss!';
The slowest loading workflow (need to search in all loaded modules):
import 'app.css!plugin-css';
import 'component.scss!plugin-sass';
If you keep state in store model object or in mobx
and your application will be
able to restore state from it, then you don't need this part, just keep you store
instance in separate module.
React, babel plugin, babel preset are required (obviously):
jspm install react react-dom
jspm install plugin-babel babel-preset-react --dev
We could use WebPack's react hot reloader.
jspm install npm:react-hot-loader@3.0.0-beta.5 --save-dev
React Hot Reloader v3.x is the best hot reloader and it uses the best things
from both react-transform-hmr
and react-hot-loader
v1.x - v2.x
How does it work:
react-hot-loader/babel
babel plugin is required to wrap import()
react-hot-loader/lib/patch.dev.js
is required, will patch React on the flyreact-hot-loader/lib/AppContainer.dev.js
will restore state on reload__reload()
hook required to rerender application instead of full module reloadPlease note, that react-hot-loader/babel should be FIRST plugin in list of Babel plugins.
File: jspm.config.js
:
SystemJS.config({
paths: {
"app/": "src/"
},
meta: {
"*.jsx": { loader: "plugin-babel" }
},
transpiler: "plugin-babel",
babelOptions: {
"presets": [
"babel-preset-react"
]
},
browserConfig: {
"babelOptions": {
"plugins": [
"react-hot-loader/babel"
]
},
"packages": {
"app": {
"main": "index.jsx"
}
}
},
packages: {
"app": {
"main": "index.dist.jsx",
"defaultExtension": "jsx"
}
}
});
File: src/index.jsx
(development entry point):
import React from 'react';
import ReactDOM from 'react-dom';
import 'react-hot-loader/lib/patch.dev.js';
import AppContainer from 'react-hot-loader/lib/AppContainer.dev.js';
import App from './App';
const root = document.getElementById('root');
ReactDOM.render(<AppContainer><App /></AppContainer>, root);
export function __reload() {
ReactDOM.render(<AppContainer><App /></AppContainer>, root);
}
File: src/index.dist.jsx
(production entry point):
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
ReactDOM.render(<App/>, document.getElementById('root'));
File: ./index.html
(development entry point):
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Application</title>
</head>
<body>
<div id="root"></div>
<script src="jspm_packages/system.js"></script>
<script src="jspm.config.js"></script>
<script>SystemJS.import('app');</script>
</body>
</html>
File: ./index.dist.html
(production entry point):
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Application</title>
</head>
<body>
<div id="root"></div>
<script src="app.js"></script>
</body>
</html>
FAQs
SystemJS / JSPM hot reloader with support of CSS, SCSS, SASS, LESS, Stylus, React and JavaScript
We found that systemjs-hot-reloader-ex 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.