yenshih / style-resources-loader

CSS processor resources loader for webpack
MIT License
262 stars 10 forks source link

Parse error? #15

Closed Wrecker138 closed 5 years ago

Wrecker138 commented 5 years ago

Hello, could you pls explain smth for me? I have a stylus mixin in mixins.styl file and it's the reason why my custom webpack bundle throw a parse error I don't really understand what's the problem because my another bundle (on gulp though) doesn't have such problem

Here's the mixin

`

   textSizing($fsS,$lhS,$fsE,$lhE,$wS,$wE)
         font-size: unit($fsS, 'px')
         line-height: unit($lhS, 'px')
        @media screen and (max-width: unit($wS, 'px')) // - line which causes trouble with parcer
        $gDiff = '(100vw - %s)' % unit($wE, 'px');
        $wDiff = ($wS - $wE);
         $fsDiff = ($fsS - $fsE);
         $lhDiff = ($lhS - $lhE);
         $fsF = s('calc(%s / %s  * %s + %s)',$gDiff, $wDiff, $fsDiff, unit($fsE, 'px'))
         $lhF = s('calc(%s / %s  * %s + %s)',$gDiff, $wDiff, $lhDiff, unit($lhE, 'px'))

        font-size: $fsF
        line-height: $lhF 

`

Here's how it made in config `

{ loader: 'style-resources-loader', options: { patterns: [ path.resolve(dirname, './src/styles/variables.styl'), path.resolve(dirname, './src/styles/mixins.styl'), path.resolve(dirname, './src/styles/optimize.styl'), path.resolve(dirname, './src/styles/global.styl'), path.resolve(dirname, './src/views/header/header.styl'), path.resolve(dirname, './src/views/footer/footer.styl'), path.resolve(__dirname, './src/styles/libs/*.styl'), ], injector: (source, resources) => { const combineAll = type => resources .filter(({ file }) => file.includes(type)) .map(({ content }) => content) .join('');

            return combineAll('variables') + combineAll('mixins') + combineAll('optimize') + combineAll('global') + combineAll('header') + combineAll('footer') + source;
        }
      }
    }

`

yenshih commented 5 years ago

Sorry for the late reply. Maybe you can join those resources content with \n, or ensure each resource files have \n character at last. If not, files concatenation will probably cause a parse error.