SolidZORO / next-plugin-antd-less

🎩 Use Antd (Less) with Next.js v12, Zero Dependency on other Next-Plugins.
MIT License
345 stars 48 forks source link

why global less only can be imported by 'require' not 'import' ? #76

Closed tonyjeffreyIn closed 2 years ago

SolidZORO commented 2 years ago

I remember that nextjs was defined in this way before, but I don't know if it has been improved. You can try.

esymeptoo commented 2 years ago

module.exports = function ({ types: t }) { return { name: 'replace-less-import-to-require', visitor: { ImportDeclaration(path){ const { node } = path; if (!node) return; const { value } = node.source; if (!value || !/\.less$/.test(value)) { return; } path.replaceWithSourceString(require('${value}')); } } } } you can define a babel plugin to replace import to 'require' syntax