【发布时间】:2020-01-04 19:58:13
【问题描述】:
我必须根据登录页面和所有其他页面动态导入某些样式列表。 但是从登录页面导航到另一个页面时,我必须卸载引导样式,因为引导与 myStyle 冲突:
// if we are in landing page then load bootstrap otherwise load myStyle
if (props.location.pathname === '/') {
import(`./assets/css/bootstrap.css`);
} else {
import(`./assets/css/myStyle.css`);
}
这是我迄今为止尝试过的,但它没有做任何事情。(由于风格冲突,我的主题崩溃了) 我想要的是一种在页面中完全动态卸载样式的方法。
if (props.location.pathname === '/') {
delete require.cache[require.resolve('./assets/css/myStyle.css')];
import(`./assets/css/bootstrap.css`);
} else {
delete require.cache[require.resolve('./assets/css/bootstrap.css')];
import(`./assets/css/myStyle.css`);
}
Webpack 是否支持这样的场景?
【问题讨论】: