Failed to import web component materials using Webpack 2

I am trying to implement the material-components-webReact application correctly with Webpack 2. I want to import Sass files so that they can be thematic.

Here are what I think are relevant parts of my configuration:

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 ran 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 Sass files load normally, but the import material-components-webdoes not work at all, but also does not cause any errors.

If I add 'material-components-web/dist/material-components-web.min.css'in entry.main, then it will work, but then I obviously cannot easily change the subject so that it seems wrong. What should I do here?

+4
source share
1

, : https://github.com/material-components/material-components-web/blob/master/docs/theming.md#step-3-changing-the-theme-with-sass 100%, , React to, , ,

@import '~material-components-web/material-components-web.scss';

@import "material-components-web/material-components-web";

webpack 2 . , .

0

Source: https://habr.com/ru/post/1673903/


All Articles