Webpack 3:如何向链式加载器添加选项?

时间:2019-07-04 07:04:05

标签: webpack webpack-3

// ...    
const webpack = require('webpack');

module.exports = function config(env, argv = {}) {
  return {
    // ...
    module: {
      loaders: [
        {
          test: /\.jsx?$/,
          include: APP_DIR,
          loader: ['babel-loader', 'eslint-loader'],
        },
        {
          test: /\.css$/,
          include: APP_DIR,
          loader: 'style-loader!css-loader',
        },
        {
          test: /\.scss$/,
          include: APP_DIR,
          loaders: [
            'style-loader',
            'css-loader', // <- is this the same thing as chaining?
            {
              loader: 'sass-loader', // <- is this the method?
              options: {
                implementation: dartSass,
              },
            },
          ],
        },
        {
          test: /\.svg$/,
          loader: 'babel-loader!react-svg-loader?' + JSON.stringify({ // <- this doesn't work
            options: {
              svgo: {
                plugins: [
                  { removeTitle: false }
                ],
              },
            },
          }),
        },
      ],
    },
  };
};

编辑:所以我需要添加

          options: {
            svgo: {
              plugins: [
                { removeTitle: false },
              ],
            },
          },

链接到react-svg-loader并保持链接

1 个答案:

答案 0 :(得分:0)

好吧,好像它在文档中一样工作。我虽然只是webpack4语法,但显然不是。 https://www.npmjs.com/package/react-svg-loader

{
  test: /\.svg$/,
  use: [
    "babel-loader",
    {
      loader: "react-svg-loader",
      options: {
        svgo: {
          plugins: [
            { removeTitle: false }
          ],
        },
      },
    },
  ],
},