My go-to for creating projects is using TypeScript and create-react-app
. I recently incorporated the typings-for-css-modules-loader
and dabbled in css-modules
as well.
{
test: /\.css$/,
use: [
require.resolve('style-loader'),
{
loader: require.resolve('typings-for-css-modules-loader'),
options: {
modules: true,
namedExport: true,
camelCase: true,
},
},
{
loader: require.resolve('postcss-loader'),
options: {
// Necessary for external CSS imports to work
// https://github.com/facebookincubator/create-react-app/issues/2677
ident: 'postcss',
plugins: () => [
require('postcss-flexbugs-fixes'),
autoprefixer({
browsers: [
'>1%',
'last 4 versions',
'Firefox ESR',
'not ie < 9', // React doesn't support IE8 anyway
],
flexbox: 'no-2009',
}),
],
},
},
],
},
As part of this setup, I also created a *.css.d.ts
file.
export const wrapper: string;
https://i.sstatic.net/VcusM.png
Despite everything, I seem to be facing the issue of css-modules
exporting empty objects:
import * as React from 'react';
import * as Styles from './LogIn.css';
import * as ReactTransitionGroup from 'react-transition-group';
import { Form, Icon, Input, Button } from 'antd';
console.log(Styles) // {}
console.log(Styles.wrapper) // undefined