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

@value's can't be imported from another file #12

Closed
edygar opened this issue Jan 8, 2016 · 5 comments
Closed

@value's can't be imported from another file #12

edygar opened this issue Jan 8, 2016 · 5 comments

Comments

@edygar
Copy link

edygar commented Jan 8, 2016

I'm trying to use a @value in the selector but currently it doesn't work,the hash is propagated instead (eg: i__const_borderColor_288) in the following code:

@value featured-light-text-color as borderColor from "styles/colors";

/* it can't be import values due a bug */
@svg-load bgImage url('./image.svg') {
  polygon, line {
    stroke: borderColor;
  }
}

When using local values, it works:

@value borderColor: #F00;

/* it can't be import values due a bug */
@svg-load bgImage url('./image.svg') {
  polygon, line {
    stroke: borderColor;
  }
}
@TrySound
Copy link
Owner

TrySound commented Jan 8, 2016

@edygar Try to process only with css-modules and show me result.

@TrySound
Copy link
Owner

TrySound commented Jan 8, 2016

Also show your build code.

@edygar
Copy link
Author

edygar commented Jan 8, 2016

First, thank you, for both this plugin and for the fast support!


I tried to isolate postcss-inline-svg, but the result was the same

The CSS Sources:

/* colors.css */
@value main-brand-color: #BB9256;
@value secondary-brand-color: #161D2F;
@value featured-light-text-color: main-brand-color;
/* styles.css */
@value secondary-brand-color as bgColor from "styles/colors";
@value featured-light-text-color as borderColor from "styles/colors";

@svg-load bgTitle1 url('./image.svg') {
  polygon, line {
    stroke: borderColor;
    fill: bgColor;
  }
}
@svg-load bgTitle2 url('./image-2.svg') {
  polygon, line {
    stroke: borderColor;
    fill: bgColor;
  }
}

.bgTitle {
  margin: 0 auto;
  padding: 1px 0 1px;
  background-image:
    svg-inline(bgTitle1),
    svg-inline(bgTitle2);
  background-position: 0% 60%, 100% 60%;
  background-repeat: no-repeat;
}

As for the build code, it's too long (weback), so here is what matters:

module.exports = {
  module: {
    loaders: [
      // …
      { test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=image/svg+xml" },
      {
        test: /\.css$/,
        loaders: [
          'style-loader',
          'css-loader?' + [
            'modules',
            'sourceMap',
            'importLoaders=1',
            'localIdentName=[path]_[name]_[local]_[hash:base64:5]'
          ].join('&') ,
          'postcss-loader'
        ]
      },
      {
        test: universalizationPlugin.regular_expression('images'),
        loader: 'url-loader?limit=10240', // any image below or equal to 10K will be converted to inline base64 instead
      }
    ]
  },
  // … 
  'postcss': [
    // require('postcss-clearfix'),
    // require('postcss-nested'),
    // require('postcss-cssnext')({
    //   features: {
    //     rem: { rootValue: 10 }
    //   }
    // }),
    require('postcss-inline-svg')()
  ],
}

The resuting CSS:

.src-components-Featured-_styles_bgTitle_2AG_K {
  margin: 0 auto;
  padding: 1px 0 1px;
  background-image:
    url("data:image/svg+xml;charset=utf-8,%3C?xml version='1.0' encoding='iso-8859-1'?%3E %3C!-- Generator: Adobe Illustrator 17.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --%3E %3C!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.0//EN' 'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'%3E %3Csvg version='1.0' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' viewBox='0 0 522.152 108.489' style='enable-background:new 0 0 522.152 108.489;' xml:space='preserve'%3E %3Cg%3E %3Cpolygon fill='i__const_bgColor_14' stroke='i__const_borderColor_16' style='stroke-width:4.1396;stroke-miterlimit:10;' points='2.089,52.769 2.089,106.448 522.152,106.448'/%3E %3Cline fill='i__const_bgColor_14' stroke='i__const_borderColor_16' style='stroke-width:1.6559;stroke-miterlimit:10;' x1='2.089' y1='71.136' x2='522.152' y2='106.448'/%3E %3Cline fill='i__const_bgColor_14' stroke='i__const_borderColor_16' style='stroke-width:1.6559;stroke-miterlimit:10;' x1='2.089' y1='88.764' x2='519.476' y2='106.121'/%3E %3Cpolygon fill='i__const_bgColor_14' stroke='i__const_borderColor_16' style='stroke-width:4.1396;stroke-miterlimit:10;' points='75.328,3.013 75.328,59.692 520.814,106.284'/%3E %3Cline fill='i__const_bgColor_14' stroke='i__const_borderColor_16' style='stroke-width:1.6559;stroke-miterlimit:10;' x1='75.328' y1='22.38' x2='520.814' y2='106.284'/%3E %3Cline fill='i__const_bgColor_14' stroke='i__const_borderColor_16' style='stroke-width:1.6559;stroke-miterlimit:10;' x1='75.328' y1='42.008' x2='518.138' y2='105.957'/%3E %3C/g%3E %3C/svg%3E"),
    url("data:image/svg+xml;charset=utf-8,%3C?xml version='1.0' encoding='iso-8859-1'?%3E %3C!-- Generator: Adobe Illustrator 17.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --%3E %3C!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.0//EN' 'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'%3E %3Csvg version='1.0' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' viewBox='0 0 522.152 108.489' style='enable-background:new 0 0 522.152 108.489;' xml:space='preserve'%3E %3Cg transform='matrix(-1 0 0 1 522.152 0)'%3E %3Cpolygon fill='i__const_bgColor_14' stroke='i__const_borderColor_16' style='stroke-width:4.1396;stroke-miterlimit:10;' points='2.089,52.769 2.089,106.448 522.152,106.448'/%3E %3Cline fill='i__const_bgColor_14' stroke='i__const_borderColor_16' style='stroke-width:1.6559;stroke-miterlimit:10;' x1='2.089' y1='71.136' x2='522.152' y2='106.448'/%3E %3Cline fill='i__const_bgColor_14' stroke='i__const_borderColor_16' style='stroke-width:1.6559;stroke-miterlimit:10;' x1='2.089' y1='88.764' x2='519.476' y2='106.121'/%3E %3Cpolygon fill='i__const_bgColor_14' stroke='i__const_borderColor_16' style='stroke-width:4.1396;stroke-miterlimit:10;' points='75.328,3.013 75.328,59.692 520.814,106.284'/%3E %3Cline fill='i__const_bgColor_14' stroke='i__const_borderColor_16' style='stroke-width:1.6559;stroke-miterlimit:10;' x1='75.328' y1='22.38' x2='520.814' y2='106.284'/%3E %3Cline fill='i__const_bgColor_14' stroke='i__const_borderColor_16' style='stroke-width:1.6559;stroke-miterlimit:10;' x1='75.328' y1='42.008' x2='518.138' y2='105.957'/%3E %3C/g%3E %3C/svg%3E");
  background-position: 0% 60%, 100% 60%;
  background-repeat: no-repeat;
}

The resulting SVG:

<?xml version='1.0' encoding='iso-8859-1'?> <!-- Generator: Adobe Illustrator 17.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> <!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.0//EN' 'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'> <svg version='1.0' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' viewBox='0 0 522.152 108.489' style='enable-background:new 0 0 522.152 108.489;' xml:space='preserve'> <g transform='matrix(-1 0 0 1 522.152 0)'> <polygon fill='i__const_bgColor_14' stroke='i__const_borderColor_16' style='stroke-width:4.1396;stroke-miterlimit:10;' points='2.089,52.769 2.089,106.448 522.152,106.448'/> <line fill='i__const_bgColor_14' stroke='i__const_borderColor_16' style='stroke-width:1.6559;stroke-miterlimit:10;' x1='2.089' y1='71.136' x2='522.152' y2='106.448'/> <line fill='i__const_bgColor_14' stroke='i__const_borderColor_16' style='stroke-width:1.6559;stroke-miterlimit:10;' x1='2.089' y1='88.764' x2='519.476' y2='106.121'/> <polygon fill='i__const_bgColor_14' stroke='i__const_borderColor_16' style='stroke-width:4.1396;stroke-miterlimit:10;' points='75.328,3.013 75.328,59.692 520.814,106.284'/> <line fill='i__const_bgColor_14' stroke='i__const_borderColor_16' style='stroke-width:1.6559;stroke-miterlimit:10;' x1='75.328' y1='22.38' x2='520.814' y2='106.284'/> <line fill='i__const_bgColor_14' stroke='i__const_borderColor_16' style='stroke-width:1.6559;stroke-miterlimit:10;' x1='75.328' y1='42.008' x2='518.138' y2='105.957'/> </g> </svg>

@TrySound
Copy link
Owner

TrySound commented Jan 8, 2016

@edygar Never worked with webpack and css-modules. And I think it's not inline-svg issue. Try to ask in their issues.

@edygar
Copy link
Author

edygar commented Jan 8, 2016

@TrySound, ok. I'm gonna start with the css-loader.

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