我正在使用 typescript 构建基本的 React 应用程序,但无法导入 CSS 文件索引.tsx file
我能够导入索引.css文件如下:
import './index.css';
//this import gives typescript error when running webpack
但无法导入为
import * as Styles from './index.css';
这是我的webpack.config.js file
var path = require("path");
var HtmlWebpackPlugin = require('html-webpack-plugin')
var config = {
mode:"none",
entry:"./src/index.tsx",
output:{
path: path.resolve(__dirname,"dist"),
filename: "bundle.js"
},
resolve:{
extensions:[".ts", ".tsx", ".js"]
},
module:{
rules:[
{test:/\.tsx?$/, loader:"awesome-typescript-loader"},
{ test: /\.css$/, include: path.join(__dirname, 'src/'),
loader:"typings-for-css-modules-loader" }
]
},
plugins:[new HtmlWebpackPlugin({
template: './index.html'
})]
};
module.exports = config;
我在发布之前尝试点击链接,但没有成功
如何在 .tsx 打字稿中包含 .css 文件? https://stackoverflow.com/questions/41628247/how-to-include-css-file-in-tsx-typescript
如何将 css 文件导入到组件 .jsx 文件中 https://stackoverflow.com/questions/37143885/how-to-import-css-file-for-into-component-jsx-file/37144690#37144690
https://github.com/parcel-bundler/parcel/issues/616 https://github.com/parcel-bundler/parcel/issues/616
提前致谢