Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(module): support module.rules for webpack 2 #154

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/properties/module/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,21 @@ const loaderSchemaFn = ({ rules }) => {
},
},
}),
use: Joi.array().items(
Joi.string(),
Joi.object({
loader: Joi.string().required(),
options: Joi.object(),
})
).options({
language: {
array: {
includes: LOADER_IN_LOADERS_MESSAGE,
},
},
}),
})
.xor('loaders', 'loader')
.xor('loaders', 'loader', 'use')
.nand('loaders', 'query')
.options({ language: { object: { nand: LOADERS_QUERY_MESSAGE } } })

Expand Down Expand Up @@ -96,9 +109,10 @@ export default (options) => {
const loaderSchema = loaderSchemaFn(options)
const loadersSchema = Joi.array().items(loaderSchema)
return Joi.object({
loaders: loadersSchema.required(),
loaders: loadersSchema,
rules: loadersSchema,
preLoaders: loadersSchema,
postLoaders: loadersSchema,
noParse: Joi.array(Joi.object().type(RegExp)).single(),
})
}).xor('loaders', 'rules')
}
77 changes: 75 additions & 2 deletions src/properties/module/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,72 @@ const validModuleConfigs = [
],
},
},
{
input: {
rules: [
{ test: 'foo', include: /src/, loader: 'babel' },
],
},
},
{
input: {
rules: [
{ test: /\.less$/, loader: 'style-loader!css-loader!autoprefixer-loader!less-loader' },
],
},
},
{
input: {
rules: [
{ test: /\.(?:eot|ttf|woff2?)$/, use: ['file-loader'] },
],
},
},
{
// should allow both `include` and `exclude with the rule 'loader-enforce-include-or-exclude'
input: {
rules: [{ test: /foo/, loader: 'foo', include: 'foo', exclude: 'bar' }],
},
schema: schemaFn({ rules: { 'loader-enforce-include-or-exclude': true } }),
},
{
// should be fine with `include` with rule 'loader-enforce-include-or-exclude'
input: {
rules: [{ test: /foo/, loader: 'foo', include: 'foo' }],
},
schema: schemaFn({ rules: { 'loader-prefer-include': true } }),
},
{
// should allow mix of objects and strings in `loaders` array
input: {
rules: [
{
test: /foo/,
use: ['style-loader', { loader: 'file-loader' }],
},
],
},
},
{
input: {
rules: [
{
test: /\.css$/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader', options: { modules: true } },
],
},
],
},
},
]

const invalidModuleConfigs = [
{
input: {},
error: { message: '"value" must contain at least one of [loaders, rules]' },
},
{
input: {
loaders: [
Expand All @@ -93,6 +156,14 @@ const invalidModuleConfigs = [
},
error: { message: '"loaders" must be an array' },
},
{
input: {
loaders: [
{ test: /\.less$/, use: 'style-loader!css-loader!autoprefixer-loader!less-loader' },
],
},
error: { message: '"use" must be an array' },
},
{
input: {
loaders: [
Expand All @@ -114,7 +185,9 @@ const invalidModuleConfigs = [
input: {
loaders: [{ test: /\.(?:eot|ttf|woff2?)$/, loaders: ['file-loader'], loader: 'style' }],
},
error: { message: '"value" contains a conflict between exclusive peers [loaders, loader]' },
error: {
message: '"value" contains a conflict between exclusive peers [loaders, loader, use]',
},
},
{
input: {
Expand All @@ -134,7 +207,7 @@ const invalidModuleConfigs = [
input: {
loaders: [{ test: /foo/ }],
},
error: { message: '"value" must contain at least one of [loaders, loader]' },
error: { message: '"value" must contain at least one of [loaders, loader, use]' },
},
{
input: {
Expand Down