Menu

KickJS Asset Manager — Type-Safe File Resolution from Dev to Dist
📰
0

KickJS Asset Manager — Type-Safe File Resolution from Dev to Dist

DEV Community·Orinda Felix Ochieng·about 1 month ago
#kCefn7W3
#build#kickjs#typescript#assets#mails#asset
Reading 0:00
15s threshold

There is a familiar little discomfort that shows up the first time a Node.js service needs to read something off disk that is not source code. An email template. A JSON schema. A seed fixture. A vendored PDF. The first version is always a one-liner: fs.readFile(path.join(__dirname, '../templates/welcome.ejs')) . That works on your laptop. It also works in CI. And then you ship to production, your bundler flattens the output, __dirname points at dist/handlers/ instead of src/handlers/ , the relative climb misses the templates directory, and the first user who triggers a password reset gets a 500. The pragmatic fix is to scatter process.env.NODE_ENV === 'production' ? '../../dist/templates' : '../templates' across the codebase. The principled fix is to admit that on-disk assets are a build-time concern that deserves its own little type system. That is what the KickJS Asset Manager is. The shape of the problem Server-side asset resolution has three properties that conspire against you.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More