How to make SASS available to custom Webpack implementation in NextJS?











up vote
0
down vote

favorite












I'm trying to use the sass-resources-loader to have my SASS variables available in all my SASS files but it doesn't look like SASS is available to this loader.



The next-sass package docs suggest you can wrap the config object in order to make sass available to it. e.g withSass({configHere}).



However the error I get suggests that the SASS loader isn't available.



Config:



const path = require('path');
const withSass = require('
@zeit
/next-sass');

const globalSass = [
path.join(process.cwd(), 'stylesheets/variables/_variables.scss'),
path.join(process.cwd(), 'stylesheets/tools/_tools.scss')
]

module.exports = withSass({
webpack: (config, { buildId, dev, isServer, defaultLoaders }) => {
// Perform customizations to webpack config
// Important: return the modified config
config.module.rules.push({
loader: "sass-resources-loader",
options: {
resources: globalSass
}
})

return config
}
})


I am getting this error:



Module parse failed: Unexpected token (1:15)
You may need an appropriate loader to handle this file type.
> $font-size-base: 14px;
| $font-size-large: ceil(($font-size-base * 1.25));
| $font-size-small: ceil(($font-size-base * 0.85));

@multi ./node_modules/next/dist/client/next-dev


Where $font-size-base etc. are in the variables SASS file processed by "sass-resources-loader".



Could anyone suggest what I might be doing wrong here?










share|improve this question


























    up vote
    0
    down vote

    favorite












    I'm trying to use the sass-resources-loader to have my SASS variables available in all my SASS files but it doesn't look like SASS is available to this loader.



    The next-sass package docs suggest you can wrap the config object in order to make sass available to it. e.g withSass({configHere}).



    However the error I get suggests that the SASS loader isn't available.



    Config:



    const path = require('path');
    const withSass = require('
    @zeit
    /next-sass');

    const globalSass = [
    path.join(process.cwd(), 'stylesheets/variables/_variables.scss'),
    path.join(process.cwd(), 'stylesheets/tools/_tools.scss')
    ]

    module.exports = withSass({
    webpack: (config, { buildId, dev, isServer, defaultLoaders }) => {
    // Perform customizations to webpack config
    // Important: return the modified config
    config.module.rules.push({
    loader: "sass-resources-loader",
    options: {
    resources: globalSass
    }
    })

    return config
    }
    })


    I am getting this error:



    Module parse failed: Unexpected token (1:15)
    You may need an appropriate loader to handle this file type.
    > $font-size-base: 14px;
    | $font-size-large: ceil(($font-size-base * 1.25));
    | $font-size-small: ceil(($font-size-base * 0.85));

    @multi ./node_modules/next/dist/client/next-dev


    Where $font-size-base etc. are in the variables SASS file processed by "sass-resources-loader".



    Could anyone suggest what I might be doing wrong here?










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm trying to use the sass-resources-loader to have my SASS variables available in all my SASS files but it doesn't look like SASS is available to this loader.



      The next-sass package docs suggest you can wrap the config object in order to make sass available to it. e.g withSass({configHere}).



      However the error I get suggests that the SASS loader isn't available.



      Config:



      const path = require('path');
      const withSass = require('
      @zeit
      /next-sass');

      const globalSass = [
      path.join(process.cwd(), 'stylesheets/variables/_variables.scss'),
      path.join(process.cwd(), 'stylesheets/tools/_tools.scss')
      ]

      module.exports = withSass({
      webpack: (config, { buildId, dev, isServer, defaultLoaders }) => {
      // Perform customizations to webpack config
      // Important: return the modified config
      config.module.rules.push({
      loader: "sass-resources-loader",
      options: {
      resources: globalSass
      }
      })

      return config
      }
      })


      I am getting this error:



      Module parse failed: Unexpected token (1:15)
      You may need an appropriate loader to handle this file type.
      > $font-size-base: 14px;
      | $font-size-large: ceil(($font-size-base * 1.25));
      | $font-size-small: ceil(($font-size-base * 0.85));

      @multi ./node_modules/next/dist/client/next-dev


      Where $font-size-base etc. are in the variables SASS file processed by "sass-resources-loader".



      Could anyone suggest what I might be doing wrong here?










      share|improve this question













      I'm trying to use the sass-resources-loader to have my SASS variables available in all my SASS files but it doesn't look like SASS is available to this loader.



      The next-sass package docs suggest you can wrap the config object in order to make sass available to it. e.g withSass({configHere}).



      However the error I get suggests that the SASS loader isn't available.



      Config:



      const path = require('path');
      const withSass = require('
      @zeit
      /next-sass');

      const globalSass = [
      path.join(process.cwd(), 'stylesheets/variables/_variables.scss'),
      path.join(process.cwd(), 'stylesheets/tools/_tools.scss')
      ]

      module.exports = withSass({
      webpack: (config, { buildId, dev, isServer, defaultLoaders }) => {
      // Perform customizations to webpack config
      // Important: return the modified config
      config.module.rules.push({
      loader: "sass-resources-loader",
      options: {
      resources: globalSass
      }
      })

      return config
      }
      })


      I am getting this error:



      Module parse failed: Unexpected token (1:15)
      You may need an appropriate loader to handle this file type.
      > $font-size-base: 14px;
      | $font-size-large: ceil(($font-size-base * 1.25));
      | $font-size-small: ceil(($font-size-base * 0.85));

      @multi ./node_modules/next/dist/client/next-dev


      Where $font-size-base etc. are in the variables SASS file processed by "sass-resources-loader".



      Could anyone suggest what I might be doing wrong here?







      webpack sass next.js






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 at 9:04









      Antfish

      448519




      448519
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted
          +50










          I have a couple of suggestions.



          You don’t have a test for your rule:



          test: /.scss$/


          You’ll probably also need to force the sass-resources-loader to run first, before the other loaders, by using:



          enforce: 'pre'


          So, try this config:



          module.exports = withSass({
          webpack: (config, { buildId, dev, isServer, defaultLoaders }) => {
          config.module.rules.push({
          enforce: "pre",
          test: /.scss$/,
          loader: "sass-resources-loader",
          options: {
          resources: globalSass
          }
          })

          return config
          }
          })


          Hopefully this will work for you.






          share|improve this answer





















          • Awesome this worked! I think the enforce: "pre" was key. Wasn't away of this property. Thanks!
            – Antfish
            Nov 23 at 21:57










          • Glad this helped you out :)
            – Steve Holgado
            Nov 24 at 0:44











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389523%2fhow-to-make-sass-available-to-custom-webpack-implementation-in-nextjs%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote



          accepted
          +50










          I have a couple of suggestions.



          You don’t have a test for your rule:



          test: /.scss$/


          You’ll probably also need to force the sass-resources-loader to run first, before the other loaders, by using:



          enforce: 'pre'


          So, try this config:



          module.exports = withSass({
          webpack: (config, { buildId, dev, isServer, defaultLoaders }) => {
          config.module.rules.push({
          enforce: "pre",
          test: /.scss$/,
          loader: "sass-resources-loader",
          options: {
          resources: globalSass
          }
          })

          return config
          }
          })


          Hopefully this will work for you.






          share|improve this answer





















          • Awesome this worked! I think the enforce: "pre" was key. Wasn't away of this property. Thanks!
            – Antfish
            Nov 23 at 21:57










          • Glad this helped you out :)
            – Steve Holgado
            Nov 24 at 0:44















          up vote
          2
          down vote



          accepted
          +50










          I have a couple of suggestions.



          You don’t have a test for your rule:



          test: /.scss$/


          You’ll probably also need to force the sass-resources-loader to run first, before the other loaders, by using:



          enforce: 'pre'


          So, try this config:



          module.exports = withSass({
          webpack: (config, { buildId, dev, isServer, defaultLoaders }) => {
          config.module.rules.push({
          enforce: "pre",
          test: /.scss$/,
          loader: "sass-resources-loader",
          options: {
          resources: globalSass
          }
          })

          return config
          }
          })


          Hopefully this will work for you.






          share|improve this answer





















          • Awesome this worked! I think the enforce: "pre" was key. Wasn't away of this property. Thanks!
            – Antfish
            Nov 23 at 21:57










          • Glad this helped you out :)
            – Steve Holgado
            Nov 24 at 0:44













          up vote
          2
          down vote



          accepted
          +50







          up vote
          2
          down vote



          accepted
          +50




          +50




          I have a couple of suggestions.



          You don’t have a test for your rule:



          test: /.scss$/


          You’ll probably also need to force the sass-resources-loader to run first, before the other loaders, by using:



          enforce: 'pre'


          So, try this config:



          module.exports = withSass({
          webpack: (config, { buildId, dev, isServer, defaultLoaders }) => {
          config.module.rules.push({
          enforce: "pre",
          test: /.scss$/,
          loader: "sass-resources-loader",
          options: {
          resources: globalSass
          }
          })

          return config
          }
          })


          Hopefully this will work for you.






          share|improve this answer












          I have a couple of suggestions.



          You don’t have a test for your rule:



          test: /.scss$/


          You’ll probably also need to force the sass-resources-loader to run first, before the other loaders, by using:



          enforce: 'pre'


          So, try this config:



          module.exports = withSass({
          webpack: (config, { buildId, dev, isServer, defaultLoaders }) => {
          config.module.rules.push({
          enforce: "pre",
          test: /.scss$/,
          loader: "sass-resources-loader",
          options: {
          resources: globalSass
          }
          })

          return config
          }
          })


          Hopefully this will work for you.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 at 8:46









          Steve Holgado

          3,201249




          3,201249












          • Awesome this worked! I think the enforce: "pre" was key. Wasn't away of this property. Thanks!
            – Antfish
            Nov 23 at 21:57










          • Glad this helped you out :)
            – Steve Holgado
            Nov 24 at 0:44


















          • Awesome this worked! I think the enforce: "pre" was key. Wasn't away of this property. Thanks!
            – Antfish
            Nov 23 at 21:57










          • Glad this helped you out :)
            – Steve Holgado
            Nov 24 at 0:44
















          Awesome this worked! I think the enforce: "pre" was key. Wasn't away of this property. Thanks!
          – Antfish
          Nov 23 at 21:57




          Awesome this worked! I think the enforce: "pre" was key. Wasn't away of this property. Thanks!
          – Antfish
          Nov 23 at 21:57












          Glad this helped you out :)
          – Steve Holgado
          Nov 24 at 0:44




          Glad this helped you out :)
          – Steve Holgado
          Nov 24 at 0:44


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389523%2fhow-to-make-sass-available-to-custom-webpack-implementation-in-nextjs%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          TypeError: fit_transform() missing 1 required positional argument: 'X'