fullthom / parcel-2.12.0-css-imports

0 stars 0 forks source link

Change import from <script type="module">import "./app.tsx";</script> to <script type="module" src="app.tsx"></script> #1

Open ElderNE opened 4 months ago

ElderNE commented 4 months ago
moonjellydigital commented 2 months ago

The fix listed by @ElderNE will make Parcel bundle the stylesheet imported in your app.tsx file. If it doesn't seem to be working, delete the .parcel-cache and dist directories then run Parcel again.

Using static imports for stylesheets in JavaScript/TypeScript files will make Parcel bundle all the stylesheets into one file. If you want to keep the stylesheets separate, then use dynamic imports. Code below:

// Static imports for one stylesheet in your bundle.
import './app.css';
import './some-component.css';

// Dynamic imports for separate stylesheets in your bundle.
import('./app.css').then().catch((err) => {console.error(err)});
import('./some-component.css').then().catch((err) => {console.error(err)});