Skip to content

Commit

Permalink
feat: modules options now accepts object config
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
- `localIdentName` option was removed in favor `modules.localIdentName` option
- `context` option was remove in favor `modules.context` option
- `hashPrefix` option was removed in favor `modules.hashPrefix` option
- `getLocalIdent` option was removed in favor `modules.getLocalIdent` option
- `localIdentRegExp` option was removed in favor `modules.localIdentRegExp` option
  • Loading branch information
alexander-akait committed May 28, 2019
1 parent 38ff645 commit 6231f35
Show file tree
Hide file tree
Showing 12 changed files with 5,633 additions and 2,677 deletions.
237 changes: 178 additions & 59 deletions README.md

Large diffs are not rendered by default.

64 changes: 37 additions & 27 deletions src/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,45 @@
{
"type": "string",
"enum": ["local", "global"]
}
]
},
"localIdentName": {
"type": "string"
},
"localIdentRegExp": {
"anyOf": [
{
"type": "string"
},
{
"instanceof": "RegExp"
}
]
},
"context": {
"type": "string"
},
"hashPrefix": {
"type": "string"
},
"getLocalIdent": {
"anyOf": [
{
"type": "boolean"
},
{
"instanceof": "Function"
"type": "object",
"additionalProperties": false,
"properties": {
"mode": {
"type": "string",
"enum": ["local", "global"]
},
"localIdentName": {
"type": "string"
},
"localIdentRegExp": {
"anyOf": [
{
"type": "string"
},
{
"instanceof": "RegExp"
}
]
},
"context": {
"type": "string"
},
"hashPrefix": {
"type": "string"
},
"getLocalIdent": {
"anyOf": [
{
"type": "boolean"
},
{
"instanceof": "Function"
}
]
}
}
}
]
},
Expand Down
39 changes: 29 additions & 10 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,22 +267,41 @@ function getImports(messages, importUrlPrefix, loaderContext, callback) {
}

function getModulesPlugins(options, loaderContext) {
const mode = typeof options.modules === 'boolean' ? 'local' : options.modules;
let modulesOptions = {
mode: 'local',
localIdentName: '[hash:base64]',
getLocalIdent,
context: null,
hashPrefix: '',
localIdentRegExp: null,
};

if (
typeof options.modules === 'boolean' ||
typeof options.modules === 'string'
) {
modulesOptions.mode =
typeof options.modules === 'string' ? options.modules : 'local';
} else {
modulesOptions = Object.assign({}, modulesOptions, options.modules);
}

return [
modulesValues,
localByDefault({ mode }),
localByDefault({ mode: modulesOptions.mode }),
extractImports(),
modulesScope({
generateScopedName: function generateScopedName(exportName) {
const localIdentName = options.localIdentName || '[hash:base64]';
const customGetLocalIdent = options.getLocalIdent || getLocalIdent;

return customGetLocalIdent(loaderContext, localIdentName, exportName, {
regExp: options.localIdentRegExp,
hashPrefix: options.hashPrefix || '',
context: options.context,
});
return modulesOptions.getLocalIdent(
loaderContext,
modulesOptions.localIdentName,
exportName,
{
context: modulesOptions.context,
hashPrefix: modulesOptions.hashPrefix,
regExp: modulesOptions.localIdentRegExp,
}
);
},
}),
];
Expand Down
117 changes: 0 additions & 117 deletions test/__snapshots__/errors.test.js.snap

This file was deleted.

150 changes: 0 additions & 150 deletions test/__snapshots__/getLocalIdent-option.test.js.snap

This file was deleted.

Loading

0 comments on commit 6231f35

Please sign in to comment.