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

Requires a patch for use with Create React App #5

Closed
thclark opened this issue Apr 16, 2019 · 1 comment
Closed

Requires a patch for use with Create React App #5

thclark opened this issue Apr 16, 2019 · 1 comment

Comments

@thclark
Copy link

thclark commented Apr 16, 2019

Problem

The example, which gives:

const style = require('raw!./my-csl-style.csl');
const locale = require('raw!./my-xml-locale.xml');

Which doesn't work with ES6 and Create-React-App:

Failed to compile.

./src/components/Fields/ReferenceField/index.jsx
  Line 17:  Unexpected '!' in 'raw!./my-csl-style.csl'. Do not use import syntax to configure webpack loaders   import/no-webpack-loader-syntax
  Line 18:  Unexpected '!' in 'raw!./my-xml-locale.xml'. Do not use import syntax to configure webpack loaders  import/no-webpack-loader-syntax

Cause

The issue is rooted in CRA's webpack config, which defines a URL loader by default (for files other than .js, .css extensions). There is a proposal out with the CRA team to fix this (currently still open, as I write)

Workaround

The style and locale xml need to be loaded as strings and passed to the Bibliography component. This could be done with a fetch() to get their contents from a url. Instead, I've chosen to use the raw.macro library to embed the strings into my bundle, at build time, using babel.

Here's what I do:

npm install --save raw.macro

And at the top of my file (with the relevant style files in my assets directory):

import raw from 'raw.macro'
const style = raw('assets/csl/apa-style.csl')
const locale = raw('assets/csl/xml-locale.xml')

Hope this helps!

@robindemourat
Copy link
Owner

Hello, thank you for the feedback ! just updated the README examples with your method which is indeed more compatible with CRA usage (8b43e49)

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

No branches or pull requests

2 participants