@leomax/webpack
v0.0.1
Published
## API
Downloads
3
Readme
@leomax/webpack
API
Rule
Правило обработки какого-либо типа файла
Интерфейсы и типы
type TUseEntry = string | IUseEntry;
type TRuleOptions = TUseEntry | IRuleSchema;
interface IUseEntry {
loader: string;
options?: any;
}
interface IRuleSchema {
test?: Condition;
issuer?: Condition;
include?: Condition;
exclude?: Condition;
resource?: Condition;
use?: TUseEntry[];
loader?: string;
options?: any;
oneOf?: IRuleSchema;
rules?: IRuleSchema;
enforce?: 'pre' | 'post';
noParse?: RegExp | RegExp[];
}
class Rule (name: string, options: TRuleOptions);
Использование
// Простейшее правило (имя лоадера строкой)
new Rule('typescript-without-extension', 'ts-loader');
// Одиночный лоадер с указанием расширения файла
new Rule('js-babel', {
test: /\.js$/,
loader: 'babel-loader'
});
// Несколько лоадеров
new Rule('rule-with-multiple-loaders', {
test: /\.css$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: true
}
}
]
});
// Вложенные правила (стандартный вариант)
new Rule('deep-rule', {
test: /\.jsx?$/,
exclude: /node_modules/,
rules: [
{
enforce: 'pre',
loader: 'eslint-loader'
}, {
loader: 'babel-loader',
options: {
presets: ['es2015', 'stage-0', 'react']
}
}
]
});
// Вложенные правила (подклассы и упрощенная запись)
new Rule('deep-rule-more', {
test: /\.jsx?$/,
exclude: /node_modules/,
rules: [
new Rule('deep-rule-eslint', {
enforce: 'pre',
loader: 'eslint-loader'
}),
'babel-loader'
]
});
Entry
Класс для манипуляция над точками входа