I'm trying to use CSS module with Typescript.
I tried with this configuration.
Webpack config
const path = require("path");
module.exports = {
entry: "./client/index.tsx",
output: {
filename: "bundle.js",
path: __dirname + "/dist"
},
// Enable sourcemaps for debugging webpack's output.
devtool: "source-map",
resolve: {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: [".ts", ".tsx", ".js", ".json", ".css"]
},
module: {
rules: [
{ test: /\.css$/, loader: 'typings-for-css-modules?modules' },
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
{
test: /\.tsx?$/, loader: "ts-loader", options: {
configFile: __dirname + "/tsconfig.client.json"
}
},
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{ enforce: "pre", test: /\.js$/, loader: "source-map-loader" }
]
},
};
I want to use CSS module with style codes written in Stylus. Therefore, I can't use typescript language service for this purpose.
I don't mind not to use this webpack plugin. If there are alternative solution, welcome to comment. I want to know best practice around this!
Other files
There are ./client/index.tsx and ./client/test.css with this code.
./client/index.tsx
import * as React from "react";
import * as ReactDOM from "react-dom";
import * as CSS from "./test.css";
class ControlPanelRoot extends React.Component<any, any> {
public render() {
return (
<div>
<img src="../public/logo.png" />
</div>
);
}
}
./client/test.css
.aa{
height: 100px;
color: white;
}
.bb{
display: inline;
}
But there was no definition file generated.