module: {
rules: [
{
test: /\.css/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader' }
]
}
]
}
import 'style-loader!css-loader!style.css';
[
{ type: 'javascript/auto', resolve: {} },
{ test: /\.mjs$/i,type: 'javascript/esm',resolve: { mainFields: [Array] } },
{ test: /\.json$/i, type: 'json' },
{ test: /\.wasm$/i, type: 'webassembly/experimental' }
]
class NormalModuleFactory {
this.ruleSet = new RuleSet(options.defaultRules.concat(options.rules));
}
static normalizeRule(rule, refs, ident) {
let condition = {
test: rule.test,
include: rule.include,
exclude: rule.exclude
};
newRule.resource = RuleSet.normalizeCondition(condition);
}
static normalizeCondition(condition) {
if (typeof condition === "string") {
return str => str.indexOf(condition) === 0;
}
if (typeof condition === "function") {
return condition;
}
if (condition instanceof RegExp) {
return condition.test.bind(condition);
}
}
static normalizeUse(use, ident) {
if (typeof use === "function") {
return data => RuleSet.normalizeUse(use(data), ident);
}
}
normalizeUse结果
[
{loader:'style-loader'},
{loader:'css-loader'}
]
rules:
[
{
resource: [Function],
resourceQuery: [Function],
use: [
{loader:'style-loader'},
{loader:'css-loader'}
]
}
]
const result = this.ruleSet.exec({
resource: resourcePath,
resourceQuery
});
[
{
type: 'use',
value: {
loader: 'style-loader',
options: {}
},
enforce: undefined
},
{
type: 'use',
value: {
loader: 'css-loader',
options: {}
},
enforce: undefined
}
]