简体   繁体   English

webpack 4 sass-loader 不生成 scss 源映射

[英]webpack 4 sass-loader not generating scss source maps

Problem Summary问题总结

I'm trying to create source maps for my scss files.我正在尝试为我的 scss 文件创建源映射。 Webpack runs and compiles scss and js fine in the setup below, but the generated js/css files lack any source maps at all no matter what I try. Webpack 在下面的设置中运行和编译 scss 和 js 很好,但是无论我尝试什么,生成的 js/css 文件都根本没有任何源映射。 I've searched around for two days looking for an answer, but my config code seems solid enough.我已经搜索了两天寻找答案,但我的配置代码似乎足够可靠。 Any idea why scss source maps wouldn't be generated at all?知道为什么根本不会生成 scss 源映射吗? I need them to pickup the scss partials as well.我也需要它们来拾取 scss 部分。

All the sourceMap: true options I've added don't seem to do anything.我添加的所有sourceMap: true选项似乎都没有做任何事情。 devtool: 'source-map' is the same, no difference. devtool: 'source-map'是一样的,没有区别。 I've tried adjusting the scss entry config to import all .scss files not just the *-main.scss files, but I was met with the same result, nothing.我尝试调整 scss 条目配置以导入所有 .scss 文件,而不仅仅是 *-main.scss 文件,但我遇到了相同的结果,什么也没有。

webpack.config.js: webpack.config.js:

const path = require('path');
const entry = require('webpack-glob-entry');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const MinifyPlugin = require("babel-minify-webpack-plugin");

module.exports = {
    entry: entry('./Pages/Themes/**/Javascript/*.js', './Pages/Themes/**/Scss/*-main.scss'),
    mode: 'development',
    output: {
        path: path.resolve(__dirname, 'wwwroot/bundles/js/'),
        filename: '[name].bundle.js',
    },
    watch: true,
    devtool: 'source-map',
    module: {
        rules: [
            {
                test: /\.js$/,
                use: 'babel-loader',
                exclude: /node_modules/
            },
            {
                test: /\.scss$/,
                use: [
                    'style-loader',
                    {
                        loader: MiniCssExtractPlugin.loader,
                        options: {
                            sourceMap: true,
                        }
                    },
                    {
                        loader: 'css-loader',
                        options: {
                            sourceMap: true,
                        }
                    },
                    {
                        loader: 'postcss-loader',
                        options: {
                            plugins: [
                                require('autoprefixer'),
                                require('cssnano')
                            ],
                            sourceMap: true,
                        }
                    },
                    {
                        loader: 'sass-loader',
                        options: {
                            sourceMap: true,
                        }
                    }
                ],
            }
        ]
    },
    plugins: [
        new MinifyPlugin(),
        new MiniCssExtractPlugin({
            filename: '../css/[name].css',
            sourceMap: true
        })
    ]
};


The code above outputs like so:上面的代码输出如下:

  • bundles捆绑
    • css css
      • theme-main.css主题-main.css
    • js js
      • theme-main.bundle.js主题-main.bundle.js

I had the same problem.我有同样的问题。 I solved it with the following configuration.我用以下配置解决了它。

devtool: 'source-map',
  module: {
    rules: [
      {
        test: /\.(sa|c|sc)ss$/,
        use: [
          'style-loader',
          {
            loader: 'css-loader',
            options: {
              sourceMap: true
            }
          },
          {
            loader: 'sass-loader',
            options: {
              sourceMap: true,
            }
          }
        ]
      }
    ]
  }

I hope it helps you Regards.我希望它可以帮助你问候。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM