Sho*_*ngs 17 javascript tailwind-css vite
构建 Vite2 应用程序。
试图导入一个ESModulein tailwind.config.js. 该模块的导出方式如下:
export default xxx;
Run Code Online (Sandbox Code Playgroud)
然后我导入了该模块,如下tailwind.config.js所示:
const xx = require('./xx/xxx');
Run Code Online (Sandbox Code Playgroud)
但我收到一个错误:
[plugin:vite:css] Cannot use import statement outside a module
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
Sho*_*ngs 37
我从 Vite Discord 频道得到了答复。这是将 postcss 和 tailwindcss 配置文件转换为 ESModule 的解决方案。
执行此操作,您就可以import在这些配置文件中使用。
tailwind.config.js
export default {
purge: ['./*.html', './src/**/*.{vue,js,ts,jsx,tsx,css}'],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
}
Run Code Online (Sandbox Code Playgroud)
postcss.config.js
import tailwind from 'tailwindcss'
import autoprefixer from 'autoprefixer'
import tailwindConfig from './tailwind.config.js'
export default {
plugins: [tailwind(tailwindConfig), autoprefixer],
}
Run Code Online (Sandbox Code Playgroud)
我添加了 vite.config.jsimport postcss from './postcss.config.js' 和
css: {
postcss,
},
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15826 次 |
| 最近记录: |