Vid*_*dya 7 css node-modules reactjs webpack parceljs
我目前正在将使用 Webpack 构建的 React 项目迁移到 Parcel 中,作为一个实验,看看炒作到底是什么。该项目使用Reactstrap,它有Bootstrap作为依赖项。
我有一个main.tsx文件,它是应用程序中大多数其他页面的“外壳”,它从 node_modules 导入 Bootstrap CSS,如下所示:
import * as React from "react";
import 'bootstrap/dist/css/bootstrap.min.css'; // <-- There it is!
...
Run Code Online (Sandbox Code Playgroud)
这对于 Webpack 来说工作得很好,当我构建一个使用main.tsxParcel 导入(大概还有它附带的 Boostrap CSS)的文件时,没有错误。然而,页面上没有 Bootstrap CSS,所以看起来很奇怪。
尽管 Parcel 标榜自己是“零配置”,但我是否需要添加一些配置才能让 Parcel 处理和导入该 CSS?
首先,您的 React/Parcel 项目需要具有以下结构:
root
|- node_modules
|- src
| |- styles.scss
| |_ main.tsx
|
|- .sassrc
|_ package.json
Run Code Online (Sandbox Code Playgroud)
在.sassrc中定义 includePaths :
// file : .sassrc
{
"includePaths": [
"node_modules/",
"src/"
]
}
Run Code Online (Sandbox Code Playgroud)
在styles.scss中导入bootstrap
// file : styles.scss
@import '../node_modules/bootstrap/scss/bootstrap';
Run Code Online (Sandbox Code Playgroud)
然后在main.tsx中导入您的styles.scss
// file : main.tsx
import * as React from 'react';
import '~/styles.scss';
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2398 次 |
| 最近记录: |