Webpack loader aliases?

拟墨画扇 提交于 2019-12-04 03:35:43

resolveLoader.alias will work here. Ie.

resolveLoader: {
    alias: {
        'with-modules': 'loader definition goes here',
    }
}

Using this configuration you can do simply

require('with-modules!./foo.scss');

at your code.

The resolveLoader.alias might work in the given case, since you are using a plugin as the loader. However if you need to use a chain of loaders, it will not work. (There's a feature request on it: https://github.com/webpack/webpack/issues/2772).

Instead you can add a parameter to the file in the require statement

var styles = require('./foo.scss?modules');

And create a new loader rule:

module: {
    loaders: [
        ...
        { test: /\.scss$/, loader: 'style!css!postcss!sass' },
        { test: /\.scss\?modules$/, loader: 'style!css?modules!postcss!sass' }
    ]
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!