Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ import refresh from 'rollup-plugin-react-refresh';
module.exports = {
plugins: [
process.env.NODE_ENV === 'development' && refresh()
// If your "react-refresh" is not installed directly next to "rollup-plugin-react-refresh" You might need to pass the option "reactRefreshRuntimeFilePathRelativeToPlugin".
// See https://github.com/PepsRyuu/rollup-plugin-react-refresh/pull/10
// process.env.NODE_ENV === 'development' && refresh({
// reactRefreshRuntimeFilePathRelativeToPlugin: 'path/to/some/other/node_modules/react-refresh/cjs/react-refresh-runtime.development.js'
// })
]
}
```
Expand Down
27 changes: 24 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
let fs = require('fs');

let runtime = fs.readFileSync(require.resolve('react-refresh/cjs/react-refresh-runtime.development.js'), 'utf8');

runtime = runtime.replace('process.env.NODE_ENV', JSON.stringify(process.env.NODE_ENV));
const DEFAULT_REACT_REFRESH_PATH = '../react-refresh/cjs/react-refresh-runtime.development.js';

function ReactRefresh (opts = {}) {
opts.reactRefreshRuntimeFilePathRelativeToPlugin = (
opts.reactRefreshRuntimeFilePathRelativeToPlugin ||
DEFAULT_REACT_REFRESH_PATH
);

let runtime;
try {
runtime = fs.readFileSync(require.resolve(opts.reactRefreshRuntimeFilePathRelativeToPlugin), 'utf8');
}
catch(e) {
throw new Error(
`[rollup-plugin-react-refresh] ERROR
Node.js forces "rollup-plugin-react-refresh" to require "react-refresh" via a relative import.
It seems like the ${opts.reactRefreshRuntimeFilePathRelativeToPlugin == DEFAULT_REACT_REFRESH_PATH ? 'default ': ''}path "${opts.reactRefreshRuntimeFilePathRelativeToPlugin}" did not resolve the file.".
The resolution has to be from the "rollup-plugin-react-refresh" plugin folder at: "${__dirname}".
Please fix the plugin option "reactRefreshRuntimeFilePathRelativeToPlugin".
See https://github.com/PepsRyuu/rollup-plugin-react-refresh/pull/10 for more info.`,
{cause: e}
);
}

runtime = runtime.replace('process.env.NODE_ENV', JSON.stringify(process.env.NODE_ENV));

return {
nollupBundleInit () {
return `
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rollup-plugin-react-refresh",
"version": "0.0.3",
"version": "0.0.4-custom",
"main": "index.js",
"author": "Paul Sweeney",
"license": "MIT",
Expand Down