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

fix: tsup watch mode not refreshing on css change #359

Merged
merged 1 commit into from
Mar 25, 2024
Merged
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
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"lucide-react": "^0.298.0",
"ts-jest": "^29.1.1",
"tsconfig": "*",
"tsup": "^6.7.0",
"tsup": "^8.0.2",
"tsup-config": "*",
"typescript": "^4.5.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-heading-analyzer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"eslint": "^7.32.0",
"eslint-config-custom": "*",
"tsconfig": "*",
"tsup": "^6.7.0",
"tsup": "^8.0.2",
"tsup-config": "*",
"typescript": "^4.5.2"
},
Expand Down
66 changes: 3 additions & 63 deletions packages/tsup-config/index.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,10 @@
import fs from "fs";
import path from "path";
import postcss from "postcss";
import postcssModules from "postcss-modules";

const config = {
dts: true,
format: "cjs",
inject: ["../tsup-config/react-import.js"],
esbuildPlugins: [
{
name: "css-module",
setup(build): void {
build.onResolve(
{ filter: /\.module\.css$/, namespace: "file" },
(args) => ({
path: `${path.join(args.resolveDir, args.path)}#css-module`,
namespace: "css-module",
pluginData: {
pathDir: path.join(args.resolveDir, args.path),
},
})
);
build.onLoad(
{ filter: /#css-module$/, namespace: "css-module" },
async (args) => {
const { pluginData } = args as {
pluginData: { pathDir: string };
};

const source = fs.readFileSync(pluginData.pathDir, "utf8");

let cssModule = {};
const result = await postcss([
postcssModules({
getJSON(_, json) {
cssModule = json;
},
}),
]).process(source, { from: pluginData.pathDir });

return {
pluginData: { css: result.css },
contents: `import "${
pluginData.pathDir
}"; export default ${JSON.stringify(cssModule)}`,
};
}
);
build.onResolve(
{ filter: /\.module\.css$/, namespace: "css-module" },
(args) => ({
path: path.join(args.resolveDir, args.path, "#css-module-data"),
namespace: "css-module",
pluginData: args.pluginData as { css: string },
})
);
build.onLoad(
{ filter: /#css-module-data$/, namespace: "css-module" },
(args) => ({
contents: (args.pluginData as { css: string }).css,
loader: "css",
})
);
},
},
],
loader: {
".css": "local-css",
},
};

export default config;
2 changes: 1 addition & 1 deletion packages/tsup-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"dependencies": {
"tsconfig": "*",
"tsup": "^6.7.0",
"tsup": "^8.0.2",
"typescript": "^4.5.2",
"postcss": "^8.4.24",
"postcss-modules": "^6.0.0"
Expand Down
Loading
Loading