Skip to content

Commit

Permalink
Merge pull request #14 from takuma-ru/feature/13
Browse files Browse the repository at this point in the history
🐛 hmr does not work in vite development environment
  • Loading branch information
takuma-ru authored Jun 13, 2024
2 parents 3988b8b + c9dd0c4 commit 601a8ef
Showing 1 changed file with 16 additions and 33 deletions.
49 changes: 16 additions & 33 deletions packages/unplugin/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,48 +27,31 @@ export const unpluginFactory: UnpluginFactory<Options | undefined> = (
enforce: "pre",

resolveId(id, importer) {
if (
fileType.some(
(type) => id.includes(type) && id.endsWith(QUERY_PARAM_NAME)
)
) {
const isLitSass = fileType.some(
(type) => id.includes(type) && id.endsWith(QUERY_PARAM_NAME)
);

if (isLitSass) {
const newId = id.replace(QUERY_PARAM_NAME, CONVERTED_FILE_TYPE);

// importerのパスを保存
if (importer) {
this.addWatchFile(importer);
if (!importer) {
return newId;
}

return newId;
return resolve(dirname(importer), newId);
}
},

load(id) {
if (id.endsWith(CONVERTED_FILE_TYPE)) {
// importerのパスを取得
const importer = this.getWatchFiles();

const content = importer
.map((importer) => {
// 相対パスを絶対パスに変換
const absoluteId = resolve(
dirname(importer),
id.replace(CONVERTED_FILE_TYPE, "")
);

let content: string | undefined;

try {
content = readFileSync(absoluteId, "utf-8");
} catch (error) {
content = undefined;
}

return content;
})
.filter((content) => content) as unknown as string[];

return content[0];
try {
const originalId = id.replace(CONVERTED_FILE_TYPE, "");

this.addWatchFile(originalId);
return readFileSync(originalId, "utf-8");
} catch (error) {
return undefined;
}
}
},

Expand Down

0 comments on commit 601a8ef

Please sign in to comment.