Skip to content

Error importing scss file #708

Closed
Closed

Description

need help with "You may need an appropriate loader to handle this file type."

in compontent file:
import "../src/components/Header.scss";

here is my webpack config:

const BASE_CSS_LOADER = "css?sourceMap&-minimize";

webpackConfig.module.loaders.push({
  test: /\.scss$/,
  exclude: null,
  loaders: [
    "style",
    BASE_CSS_LOADER,
    "postcss",
    "sass?sourceMap",
  ],
});
webpackConfig.module.loaders.push({
  test: /\.css$/,
  exclude: null,
  loaders: [
    "style",
    BASE_CSS_LOADER,
    "postcss",
  ],
});
webpackConfig.sassLoader = {
  includePaths: project.paths.client("styles"),
};

// File loaders
/* eslint-disable */
webpackConfig.module.loaders.push(
  { test: /\.woff(\?.*)?$/,  loader: "url?prefix=fonts/&name=[path][name].[ext]&limit=10000&mimetype=application/font-woff" },
  { test: /\.woff2(\?.*)?$/, loader: "url?prefix=fonts/&name=[path][name].[ext]&limit=10000&mimetype=application/font-woff2" },
  { test: /\.otf(\?.*)?$/,   loader: "file?prefix=fonts/&name=[path][name].[ext]&limit=10000&mimetype=font/opentype" },
  { test: /\.ttf(\?.*)?$/,   loader: "url?prefix=fonts/&name=[path][name].[ext]&limit=10000&mimetype=application/octet-stream" },
  { test: /\.eot(\?.*)?$/,   loader: "file?prefix=fonts/&name=[path][name].[ext]" },
  { test: /\.svg(\?.*)?$/,   loader: "url?prefix=fonts/&name=[path][name].[ext]&limit=10000&mimetype=image/svg+xml" },
  { test: /\.(png|jpg)$/,    loader: "url?limit=8192" }
)
/* eslint-enable */

// ------------------------------------
// Finalize Configuration
// ------------------------------------
// when we don't know the public path (we know it only when HMR is enabled [in development]) we
// need to use the extractTextPlugin to fix this issue:
// http://stackoverflow.com/questions/34133808/webpack-ots-parsing-error-loading-fonts/34133809#34133809
if (!__DEV__) {
  debug("Applying ExtractTextPlugin to CSS loaders.");
  webpackConfig.module.loaders.filter((loader) =>
    loader.loaders && loader.loaders.find((name) => /css/.test(name.split("?")[0]))
  ).forEach((loader) => {
    const first = loader.loaders[0];
    const rest = loader.loaders.slice(1);
    loader.loader = ExtractTextPlugin.extract(first, rest.join("!"));
    delete loader.loaders;
  });

  webpackConfig.plugins.push(
    new ExtractTextPlugin("[name].css", {
      allChunks: true,
    })
  );
}

module.exports = webpackConfig;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions