Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accept CSS string in registerPreviewStyle #1162

Merged
merged 1 commit into from
Mar 28, 2018
Merged

Conversation

erquhart
Copy link
Contributor

@erquhart erquhart commented Mar 7, 2018

- Summary

Raw styles can't currently be injected into the preview pane, which is a challenge for projects using modern build tooling. For example, I'd like to import styles from a specific file using inline webpack loaders and pass the result to registerPreviewStyle, rather than doing something hacky to get Webpack to emit files, which is next to impossible if the webpack config is shared, as in systems like Gatsby.

Adding this as a beta feature only to avoid commitment to the exact API being introduced.

- Description for the changelog

Accept CSS strings in registerPreviewStyle

- Docs

Raw CSS in registerPreviewStyle

registerPreviewStyle can now accept a CSS string, in addition to accepting a url. The feature is activated by passing in an object as the second argument, with raw set to a truthy value.This is critical for integrating with modern build tooling. Here's an example using webpack:

/**
 * Assumes a webpack project with `sass-loader` and `css-loader` installed.
 * Takes advantage of the `toString` method in the return value of `css-loader`.
 */
import CMS from 'netlify-cms';
import styles from '!css-loader!sass-loader!../main.scss'
 
CMS.registerPreviewStyle(styles.toString(), { raw: true })

@verythorough
Copy link
Contributor

verythorough commented Mar 7, 2018

Deploy preview for netlify-cms-www ready!

Built with commit a31d48e

https://deploy-preview-1162--netlify-cms-www.netlify.com

@erquhart erquhart force-pushed the raw-preview-styles branch from fa23226 to 9a5611a Compare March 7, 2018 22:29
@verythorough
Copy link
Contributor

Deploy preview for cms-demo ready!

Built with commit fa23226

https://deploy-preview-1162--cms-demo.netlify.com

@verythorough
Copy link
Contributor

verythorough commented Mar 7, 2018

Deploy preview for cms-demo ready!

Built with commit a31d48e

https://deploy-preview-1162--cms-demo.netlify.com

@erquhart erquhart force-pushed the raw-preview-styles branch from 9a5611a to dff401e Compare March 7, 2018 22:38
Copy link
Contributor

@tech4him1 tech4him1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@erquhart erquhart merged commit 79ddb3b into master Mar 28, 2018
@erquhart erquhart deleted the raw-preview-styles branch March 28, 2018 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants