Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto add useRemoteRefresh hook #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions index.js
@@ -1,3 +1,4 @@
const path = require('path')
const createServer = require('./server')

let port
Expand All @@ -15,6 +16,14 @@ module.exports = function plugin(options) {
}
}

nextConfig.webpack = (config) => {
config.module.rules.unshift({
test: /_app.*(js|jsx|ts|tsx)$/,
use: [{ loader: path.resolve(__dirname, 'loader') }],
})
return config
}

return nextConfig
}
}
10 changes: 10 additions & 0 deletions loader.js
@@ -0,0 +1,10 @@
const remoteRefreshExport = `
function RemoteRefresh(props) {
return _react["default"].createElement(App, Object.assign({}, props, { children: 'Hello World' }));
};
exports.default = RemoteRefresh;
`

module.exports = function (source) {
return source.replace('exports.default = App;', remoteRefreshExport)
}