在VITE2中,如何将ESModule导入到trawind.config.js中 [英] In Vite2, How to import an ESModule in tailwind.config.js

查看:0
本文介绍了在VITE2中,如何将ESModule导入到trawind.config.js中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

生成Vite2应用程序。

尝试在tailwind.config.js中导入ESModule。 该模块的导出方式如下:

export default xxx;

然后我在tailwind.config.jsLike:

中导入了模块
const xx = require('./xx/xxx');

但我收到一个错误:

[plugin:vite:css] Cannot use import statement outside a module

如何修复此问题?

推荐答案

我从维特不和谐频道得到了答复。这是将postcss和tawincss配置文件转换为ES模块的解决方案。

执行此操作,您可以在这些配置文件中使用import

trawind.config.js

export default {
  purge: ['./*.html', './src/**/*.{vue,js,ts,jsx,tsx,css}'],
  darkMode: false, // or 'media' or 'class'
  theme: {
    extend: {},
  },
  variants: {
    extend: {},
  },
  plugins: [],
}

postcss.config.js

import tailwind from 'tailwindcss'
import autoprefixer from 'autoprefixer'
import tailwindConfig from './tailwind.config.js'

export default {
  plugins: [tailwind(tailwindConfig), autoprefixer],
}

vite.config.js我添加了import postcss from './postcss.config.js'

css: {
  postcss,
},

这篇关于在VITE2中,如何将ESModule导入到trawind.config.js中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆