如何让Next.js同时支持导入css和less
2020-12-24 10:30
标签:href ext 项目 path ssl pru test include issues 最近在用Next.js (版本9.5.5)搭建项目时,发现css和less同时导入常常会报错,查阅一番资料后找到了一个靠谱的解决方案: 参考 https://github.com/vercel/next-plugins/issues/598#issuecomment-618461761 如何让Next.js同时支持导入css和less 标签:href ext 项目 path ssl pru test include issues 原文地址:https://www.cnblogs.com/zhaohd/p/13947803.html
在目录下新建next.config.js
文件,新增下列代码(先安装@zeit/next-less
模块)const path = require(‘path‘)
const withLess = require(‘@zeit/next-less‘)
module.exports = withLess({
lessLoaderOptions: {
javascriptEnabled: true,
// modifyVars: themeVariables,
},
webpack: (config) => {
const builtInLoader = config.module.rules.find((rule) => {
if (rule.oneOf) {
return (
rule.oneOf.find((deepRule) => {
if (deepRule.test && deepRule.test.toString().includes(‘/a^/‘)) {
return true;
}
return false;
}) !== undefined
);
}
return false;
});
if (typeof builtInLoader !== ‘undefined‘) {
config.module.rules.push({
oneOf: [
...builtInLoader.oneOf.filter((rule) => {
return (rule.test && rule.test.toString().includes(‘/a^/‘)) !== true;
}),
],
});
}
return config;
},
})
下一篇:windows编译OpenCV
文章标题:如何让Next.js同时支持导入css和less
文章链接:http://soscw.com/index.php/essay/37903.html