zahra haghi
zahra haghi

Reputation: 41

import image , css and sass file in next js

I am using react and next js.I added @zeit/next-css and @zeit/next-sass to next.config file.

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

module.exports = withCSS(withSass());

now I want to load files too.I try this but not working and got error:

module.exports = withCSS(withSass({
    webpack (config, options) {
        config.module.rules.push({
            test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
            use: {
                loader: 'url-loader',
                options: {
                    limit: 100000
                }
            }
        });

        return config;
    }
}));
_app.js:7 Uncaught Error: A cross-origin error was thrown. React doesn't have access to the actual error object in development.

I installed next-images too.but I dont know how can I config it with css and sass?

const withSass = require('@zeit/next-sass');
const withCSS = require('@zeit/next-css');
const withImages = require('next-images');

module.exports = withCSS(withSass(withImages ()));//error and not working

Upvotes: 2

Views: 2261

Answers (1)

Silambarasan
Silambarasan

Reputation: 41

You can try like this. next-compose-plugins does the trick.

  const withPlugins = require('next-compose-plugins');
  const withCSS = require("@zeit/next-css");
  const withSass = require('@zeit/next-sass');
  const withImages = require('next-images');

  module.exports = withPlugins([
    [
      withCSS(withSass({}))
    ],
    [
      withImages({})
    ],
  ])

Upvotes: 3

Related Questions