Preact CLI声称它支持CSS Modules
开箱即用。所以这就是我尝试过的;给定 2 个文件index.js
并index.module.scss
在同一个文件夹中,我尝试了这个:
index.js
import { h, Component } from 'preact';
import styles from './index.module.scss';
export default class Layout extends Component {
render() {
console.log(styles);
return (
<div className={styles.container}>
{this.props.children}
</div>
);
}
}
index.module.scss
.container {
margin: 50px auto;
max-width: 960px;
width: 100%;
}
console.log
语句打印{}
,HTML 中的属性class
为空。
我究竟做错了什么?
哦,要安装我刚刚做的这些东西
preact create default my-project
yarn add -D node-sass sass-loader