BlueBeka
BlueBeka
Explore posts from servers
TTCTheo's Typesafe Cult
Created by BlueBeka on 8/7/2024 in #questions
How to webpack? (in nextjs)
I did manage to figure this out eventually with a bit of trial and error. It's not the prettiest but it works:
if (!dev) {
// Find `next-swc-loader` which does the typescript transpilation.
let m_tsRuleSet: RuleSetRule | undefined = undefined;
tsUseLoop: for (const rule of config.module.rules) {
if (typeof rule !== 'object' || rule === null) {
continue;
}
if (rule.oneOf) {
for (const oneOfRule of rule.oneOf) {
if (typeof oneOfRule !== 'object' || oneOfRule === null) {
continue;
}
if (oneOfRule.use && Array.isArray(oneOfRule.use)) {
for (const use of oneOfRule.use) {
if (typeof use !== 'object' || use === null) {
continue;
}
if (use.loader === 'next-swc-loader') {
m_tsRuleSet = oneOfRule;
break tsUseLoop;
}
}
}
}
}
}

assert(m_tsRuleSet?.use !== undefined);
assert(Array.isArray(m_tsRuleSet.use));

m_tsRuleSet.use.unshift({
loader: "deassert/webpack-loader",
options: {
modules: ["chai"],
}
});
}
if (!dev) {
// Find `next-swc-loader` which does the typescript transpilation.
let m_tsRuleSet: RuleSetRule | undefined = undefined;
tsUseLoop: for (const rule of config.module.rules) {
if (typeof rule !== 'object' || rule === null) {
continue;
}
if (rule.oneOf) {
for (const oneOfRule of rule.oneOf) {
if (typeof oneOfRule !== 'object' || oneOfRule === null) {
continue;
}
if (oneOfRule.use && Array.isArray(oneOfRule.use)) {
for (const use of oneOfRule.use) {
if (typeof use !== 'object' || use === null) {
continue;
}
if (use.loader === 'next-swc-loader') {
m_tsRuleSet = oneOfRule;
break tsUseLoop;
}
}
}
}
}
}

assert(m_tsRuleSet?.use !== undefined);
assert(Array.isArray(m_tsRuleSet.use));

m_tsRuleSet.use.unshift({
loader: "deassert/webpack-loader",
options: {
modules: ["chai"],
}
});
}
4 replies
TTCTheo's Typesafe Cult
Created by BlueBeka on 8/7/2024 in #questions
Tailwind alias/rename utility?
For that particular one, I guess that could work. But I also have things like text-success and bg-success that would have name clashes if I try and make them both top-level
4 replies
TTCTheo's Typesafe Cult
Created by BlueBeka on 8/7/2024 in #questions
How to webpack? (in nextjs)
The tool for reference if it's relavent: https://github.com/RebeccaStevens/deassert
4 replies