question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Example of Webpack configuration?

See original GitHub issue

I’m struggling to implement this package and material-components-web properly with Webpack 2. Do any of you use it and could provide an example config that imports the mdc-web Sass files so they can be themed?

Here’s what I think are relevant parts of my config:

var webpackConfig = module.exports = {
  context: path.resolve(__dirname, '..'),
  entry: {
    'main': [
      './src/theme/main.scss',
      './src/client.js'
    ]
  },
  module: {
    rules: [
      {
        test: /\.scss$/,
        use: [
          {
            loader: 'style-loader',
          }, {
            loader: 'css-loader',
            options: {
              modules: true,
              importLoaders: 3,
              sourceMap: true,
              localIdentName: '[local]___[hash:base64:5]'
            }
          }, {
            loader: 'autoprefixer-loader',
            options: {
              browsers: 'last 2 version'
            }
          }, {
            loader: 'resolve-url-loader',
          }, {
            loader: 'sass-loader', // compiles Sass to CSS
            options: {
              outputStyle: 'expanded',
              sourceMap: true,
              includePaths: ['../src', '../node_modules', '../node_modules/@material/*']
                .map(d => path.join(__dirname, d))
                .map(g => glob.sync(g))
                .reduce((a, c) => a.concat(c), [])
            }
          },
        ],
      }
    ]
  },
  resolve: {
    modules: [
      'src',
      'node_modules'
    ],
    extensions: ['.json', '.js', '.jsx', '.scss']
  }
};

and I start my main.scss with this:

$mdc-theme-primary: #4a90e2;
$mdc-theme-accent: #f22745;
$mdc-theme-background: #fff;
@import '~material-components-web/material-components-web.scss';

All my app scss files load fine, but the material-components-web import doesn’t seem to work at all but also doesn’t throw any errors.

If I add 'material-components-web/dist/material-components-web.min.css' to entry:main then it works but then I’m obviously unable to change the theme as easily so that seems wrong. What should I do here?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
kradio3commented, Apr 4, 2017

Solution is to use two different loaders for ‘global.css’ and ‘modules’ https://github.com/css-modules/css-modules/issues/113#issuecomment-184127881 Instead of ‘global’ in regexp you can set ‘node_modules’ or ‘material-components-web’ I did’t try it, but looks fine 😃

0reactions
demiterscommented, Apr 4, 2017

Just tried it, works like a charm! Thanks! So, as a minimal config I think yours would be fine to put in docs. Not sure if many people would struggle with different setups like I did, though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuration
You may have noticed that few webpack configurations look exactly alike. This is because webpack's configuration file is a JavaScript file that exports...
Read more >
Getting Started With Webpack
An example is the sample package.json file below. Here, we use webpack to bundle the application without a configuration file:.
Read more >
All You Need to Know about Webpack in Examples
This article will cover all main ideas behind the webpack — module bundler. You will know how to configure webpack, add assets, ...
Read more >
Example Webpack Config File
An example Webpack config file with a handful of handy add-ons/plugins. Plugins. PostCSS · Autoprefixer - parse CSS and add vendor prefixes to ......
Read more >
6 ways to configure Webpack
6 ways to configure Webpack · 1. Zero Config · 2. Command Line Interface · 3. CommonJS Configuration File · 4. ESM Configuration...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found