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

Not working with create-react-app #15

Open
Danilo-Araujo-Silva opened this issue Jun 21, 2017 · 1 comment
Open

Not working with create-react-app #15

Danilo-Araujo-Silva opened this issue Jun 21, 2017 · 1 comment

Comments

@Danilo-Araujo-Silva
Copy link

Danilo-Araujo-Silva commented Jun 21, 2017

I'm trying to put this strategy to work with the facebook boilerplate create-react-app.
Unfortunally no sucess yet.

The problem I think should be simple but I created a detailed issue to describe the problem.

I tried the following:

create-react-app cssx-example

cd cssx-example

npm run eject

yarn add -D cssx-loader
yarn add react-cssx

Edited the file src/App.js from:

import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';

class App extends Component {
  render() {
    return (
      <div className="App">
        <div className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
          <h2>Welcome to React</h2>
        </div>
        <p className="App-intro">
          To get started, edit <code>src/App.js</code> and save to reload.
        </p>
      </div>
    );
  }
}

export default App;

to:

import React, { Component } from 'react';
import CSSX from 'react-cssx';

class App extends Component {
  render() {
    return (
      <CSSX styles={ this.css() }>
        <h1>Title styled with <i>CSSX</i></h1>
      </CSSX>
    );
  }

  css() {
    var color = '#BADA55';

    return (
      <style>
        h1 {
        color: {{ color }};
      }
        h1 i {
        text-decoration: underline;
      }
      </style>
    );
  }
}

export default App;

Edited the file config/webpack.dev.config.js from:

  ...
  // Process JS with Babel.
  {
    test: /\.(js|jsx)$/,
    include: paths.appSrc,
    loader: require.resolve('babel-loader'),
    options: {
      
      // This is a feature of `babel-loader` for webpack (not Babel itself).
      // It enables caching results in ./node_modules/.cache/babel-loader/
      // directory for faster rebuilds.
      cacheDirectory: true,
    },
   ...

to:

   ...
   // Process JS with Babel.
   {
     test: /\.(js|jsx)$/,
     include: paths.appSrc,
     loaders: ['cssx-loader', require.resolve('babel-loader')]
   },
   ...

Then npm start

But I got the following error:

   Failed to compile.

   ./src/App.js
   Syntax error: Unexpected token, expected } (19:17)

     17 |           <style>
     18 |             h1 {
   > 19 |             color: {{ color }};
        |                  ^
     20 |           }
     21 |             h1 i {
     22 |             text-decoration: underline;

I tried some variations like:

loaders: [require.resolve('babel-loader'), 'cssx-loader']

and

// Process JS with Babel.
{
    test: /\.(js|jsx)$/,
    include: paths.appSrc,
    loader: require.resolve('babel-loader'),
    options: {

        // This is a feature of `babel-loader` for webpack (not Babel itself).
        // It enables caching results in ./node_modules/.cache/babel-loader/
        // directory for faster rebuilds.
        cacheDirectory: true,
    },
},
// CSSX
{
    test: /\.(js|jsx)$/,
    include: paths.appSrc,
    loader: 'cssx-loader',
},

for example.

The strange thing is if I put the cssx-loader first it works for a very tiny time, then I get a compiler error.

My issue is very similar to this one.

So, how can we fix this and put CSSX to work with the create-react-app?

I'm very interested to use this approach on my project so a help would be very appreciated.

Thanks in advance.

@krasimir
Copy link
Owner

Interesting. I'll try by following your steps and will report here.

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