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

Can't build application with sass files, which are working on development #3519

Closed
jaqua opened this issue Dec 31, 2017 · 0 comments
Closed

Comments

@jaqua
Copy link

jaqua commented Dec 31, 2017

I can run my nextJS application in development mode without any errors.
I'm using SASS files for styling.
But if I try to build the productive application running next build I'm running into problems:

Module not found: Error: Can't resolve 'styles/article.sass' ...
(...) // Huge errors, which are all connected to sass files.

So I think I have to create somehow a (minified) css file from all used sass files.

This is my setup, so what is missing here?

.babelrc

{
  "env": {
    "development": {
      "presets": "next/babel",
      "plugins": [
        [
          "module-resolver", {
            "root": ["."],
            "alias": {
              "styles": "./styles"
            },
            "cwd": "babelrc"
        }],
        [
          "wrap-in-js",
          {
            "extensions": ["css$", "scss$", "sass$"]
          }
        ]
      ]
    }
  }
}

next.config.js

module.exports = {
  webpack: (config, { dev }) => {
    config.module.rules.push(
      {
        test: /\.(css|s(a|c)ss)/,
        loader: 'emit-file-loader',
        options: {
          name: 'dist/[path][name].[ext]'
        }
      },
      {
        test: /\.css$/,
        use: ['babel-loader', 'raw-loader', 'postcss-loader']
      },
      {
        test: /\.s(a|c)ss$/,
        use: ['babel-loader', 'raw-loader', 'postcss-loader',
          { loader: 'sass-loader',
            options: {
              includePaths: ['styles', 'node_modules']
                .map((d) => path.join(__dirname, d))
                .map((g) => glob.sync(g))
                .reduce((a, c) => a.concat(c), [])
            }
          }
        ]
      }
    )
    return config
  }
}
@lock lock bot locked as resolved and limited conversation to collaborators Jan 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants