Coder Social home page Coder Social logo

Comments (4)

gilesa avatar gilesa commented on August 22, 2024

I created this for a project that uses a custom webpack setup, and not create-react-app, so I haven't seen the issue you describe. If I manage to find the time, I'll take a look.

from svg-to-json-webpack-plugin.

zslabs avatar zslabs commented on August 22, 2024

I think this might have something to do with webpack-dev-server and not so much create-react-app. I'm writing the file to my source directory so I can grab specific icons from it with a tiny icon component I created:

import cx from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';

import Icons from './assets/icons/icons.json';

class Icon extends React.Component {
  getIcon = () => {
    const { icon, className, size, ...opts } = this.props;
    const classes = cx('icon', className, {
      'icon--small': size === 'small',
      'icon--large': size === 'large',
      'icon--xlarge': size === 'xlarge',
    });

    // If we find an icon
    if (Icons[icon]) {
      return (
        <svg
          xmlns="http://www.w3.org/2000/svg"
          width="24"
          height="24"
          viewBox="0 0 24 24"
          fill="none"
          strokeLinecap="round"
          strokeLinejoin="round"
          className={classes}
          {...opts}
          dangerouslySetInnerHTML={{ __html: [Icons[icon].content] }} // eslint-disable-line react/no-danger
        />
      );
    }

    console.error('Icon not found'); // eslint-disable-line no-console
    return false;
  }

  render() {
    return this.getIcon();
  }
}

Icon.propTypes = {
  className: PropTypes.string,
  icon: PropTypes.string.isRequired,
  size: PropTypes.oneOf(['small', 'large', 'xlarge']),
};

export default Icon;

but whenever I attempt to call it, the server continues to reload:

kapture 2018-04-12 at 10 51 49

from svg-to-json-webpack-plugin.

zslabs avatar zslabs commented on August 22, 2024

This looks to be an issue with how Webpack handles watching files that are created within a plugin. Using https://github.com/yessky/webpack-mild-compile resolves the issue. It appears that may be something you can add to your plugin if you wanted to work around the issue yourself webpack/watchpack#25 (comment)

from svg-to-json-webpack-plugin.

gilesa avatar gilesa commented on August 22, 2024

Great, glad you found a solution!

from svg-to-json-webpack-plugin.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.