Skip to content

Commit

Permalink
fix: fix rollup playground livereload (remix-run#3075)
Browse files Browse the repository at this point in the history
* fix: fix rollup playground livereload

* chore: add comment about .js inclusion

* chore: include .ts as well

* update comment

* update comment
  • Loading branch information
brophdawg11 authored May 6, 2022
1 parent af3bb12 commit e0d748f
Showing 1 changed file with 36 additions and 26 deletions.
62 changes: 36 additions & 26 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -868,37 +868,47 @@ export default function rollup(options) {
return builds;
}

async function triggerLiveReload(appDir) {
// Tickle live reload by touching the server entry
// Consider all of entry.server.{tsx,ts,jsx,js} since React may be used
// via `React.createElement` without the need for JSX.
let serverEntryPaths = [
"entry.server.ts",
"entry.server.tsx",
"entry.server.js",
"entry.server.jsx",
];
let serverEntryPath = serverEntryPaths
.map((entryFile) => path.join(appDir, "app", entryFile))
.find((entryPath) => fse.existsSync(entryPath));
let date = new Date();
await fs.promises.utimes(serverEntryPath, date, date);
}

function copyToPlaygrounds() {
return {
name: "copy-to-remix-playground",
async writeBundle(options, bundle) {
let playgroundsDir = path.join(__dirname, "playground");
let playgrounds = await fs.promises.readdir(playgroundsDir);
let writtenDir = path.join(__dirname, options.dir);
for (let playground of playgrounds) {
let playgroundDir = path.join(playgroundsDir, playground);
if (!fse.statSync(playgroundDir).isDirectory()) {
continue;
if (activeOutputDir === "build") {
let playgroundsDir = path.join(__dirname, "playground");
let playgrounds = await fs.promises.readdir(playgroundsDir);
let writtenDir = path.join(__dirname, options.dir);
for (let playground of playgrounds) {
let playgroundDir = path.join(playgroundsDir, playground);
if (!fse.statSync(playgroundDir).isDirectory()) {
continue;
}
let destDir = writtenDir.replace(
path.join(__dirname, "build"),
playgroundDir
);
await fse.copy(writtenDir, destDir);
await triggerLiveReload(playgroundDir);
}
let destDir = writtenDir.replace(
path.join(__dirname, "build"),
playgroundDir
);
await fse.copy(writtenDir, destDir);

// tickle live reload by touching the server entry
let serverEntry = ["tsx", "js", "jsx"].find((entryPathExtension) =>
fse.existsSync(
path.join(
playgroundDir,
"app",
`entry.server.${entryPathExtension}`
)
)
);
let serverEntryPath = path.join(playgroundDir, "app", serverEntry);
let serverEntryContent = await fse.readFile(serverEntryPath);
await fse.writeFile(serverEntryPath, serverEntryContent);
} else {
// If we're not building to "build" then trigger live reload on our
// external "playground" app
await triggerLiveReload(activeOutputDir);
}
},
};
Expand Down

0 comments on commit e0d748f

Please sign in to comment.