Webpack 3:如何向链式加载程序添加选项?
Webpack 3: How do I add options to a chained loader?
// ...
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
同时保持链接
好的,它看起来像在文档中一样工作。我虽然它只是 webpack4 语法,但显然不是。糟糕。 https://www.npmjs.com/package/react-svg-loader
{
test: /\.svg$/,
use: [
"babel-loader",
{
loader: "react-svg-loader",
options: {
svgo: {
plugins: [
{ removeTitle: false }
],
},
},
},
],
},
// ...
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
同时保持链接
好的,它看起来像在文档中一样工作。我虽然它只是 webpack4 语法,但显然不是。糟糕。 https://www.npmjs.com/package/react-svg-loader
{
test: /\.svg$/,
use: [
"babel-loader",
{
loader: "react-svg-loader",
options: {
svgo: {
plugins: [
{ removeTitle: false }
],
},
},
},
],
},