Skip to content

Commit a1a0002

Browse files
authored
Support importing npm modules to preview styles (#48)
1 parent 9a97e0e commit a1a0002

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

.changeset/cyan-turtles-sip.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
'astro-netlify-cms': minor
3+
---
4+
5+
Add support for importing npm packages via `previewStyles` config
6+
7+
⚠️ **BREAKING CHANGE** ⚠️
8+
9+
This release changes how you import a local CSS file in `previewStyles`.
10+
These must now be prefixed with a leading `/`:
11+
12+
```diff
13+
{
14+
previewStyles: [
15+
- 'src/styles/base.css',
16+
+ '/src/styles/base.css',
17+
],
18+
}
19+
```
20+
21+
This allows us to support importing CSS you may have installed from an npm module, for example importing font CSS from Fontsource:
22+
23+
```js
24+
previewStyles: ['@fontsource/roboto'];
25+
```

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ You can provide URLs to external CSS stylesheets (Google Fonts for example), pat
116116
```js
117117
previewStyles: [
118118
// Path to a local CSS file, relative to your project’s root directory
119-
'src/styles/main.css',
119+
'/src/styles/main.css',
120+
// An npm module identifier
121+
'@fontsource/roboto',
120122
// A URL to an externally hosted CSS file
121123
'https://fonts.googleapis.com/css2?family=IBM+Plex+Mono&display=swap',
122124
// Raw CSS!

demo/astro.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default defineConfig({
1111
NetlifyCMS({
1212
previewStyles: [
1313
'https://fonts.googleapis.com/css2?family=IBM+Plex+Mono&family=IBM+Plex+Sans:wght@400;700&display=swap',
14-
'src/styles/blog.css',
14+
'/src/styles/blog.css',
1515
],
1616
config: {
1717
// Use Netlify’s “Git Gateway” authentication and target our default branch

integration/vite-plugin-admin-dashboard.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function generateVirtualConfigModule({
2424
styles.push(JSON.stringify([style, opts]));
2525
} else {
2626
const name = `style__${index}`;
27-
imports.push(`import ${name} from '/${style}?raw';`);
27+
imports.push(`import ${name} from '${style}?raw';`);
2828
styles.push(`[${name}, { raw: true }]`);
2929
}
3030
});

0 commit comments

Comments
 (0)