Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(scope-plugin-options): add disableScopePlugin plugin.
  • Loading branch information
jaywcjlove committed Jun 14, 2022
1 parent 6789f87 commit 16908a9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
22 changes: 16 additions & 6 deletions packages/scope-plugin-options/README.md
Expand Up @@ -61,22 +61,32 @@ import path from 'path';
import scopePluginOptions from '@kkt/scope-plugin-options';

export default (conf, evn, options) => {
return scopePluginOptions(conf, evn, {
allowedFiles: [
path.resolve(process.cwd(), 'README.md')
]
});
return scopePluginOptions(conf, evn, false);
}
```

Disable scopePlugin

```js
import path from 'path';
import { disableScopePlugin } from '@kkt/scope-plugin-options';

export default (conf, evn, options) => {
return disableScopePlugin(conf);
}
```

### API

```ts
type ReactLibraryOptions = LoaderConfOptions & {
import { Configuration } from 'webpack';
import { LoaderConfOptions } from 'kkt';
export declare type ReactLibraryOptions = LoaderConfOptions & {
allowedFiles?: ReadonlyArray<string>;
allowedPaths?: ReadonlyArray<string>;
appSrcs?: string | ReadonlyArray<string>;
};
export default function scopePluginOptions(conf: Configuration, env: string, options: ReactLibraryOptions | false): Configuration;
```

### License
Expand Down
3 changes: 3 additions & 0 deletions packages/scope-plugin-options/package.json
Expand Up @@ -16,6 +16,9 @@
"lib",
"src"
],
"scripts": {
"watch": "tsbb watch --no-esm"
},
"devDependencies": {
"kkt": "7.1.7"
}
Expand Down
17 changes: 15 additions & 2 deletions packages/scope-plugin-options/src/index.ts
Expand Up @@ -9,15 +9,28 @@ export type ReactLibraryOptions = LoaderConfOptions & {

const regexp = /(ModuleScopePlugin)/;

export function disableScopePlugin(conf: Configuration) {
conf.resolve.plugins = conf.resolve.plugins
.map((plugin) => {
if (plugin.constructor && plugin.constructor.name && regexp.test(plugin.constructor.name)) {
return undefined;
}
return plugin;
})
.filter(Boolean);
return conf;
}

export default function scopePluginOptions(
conf: Configuration,
env: string,
options = {} as ReactLibraryOptions,
options: ReactLibraryOptions,
): Configuration {
if (!conf) {
throw Error('KKT:@kkt/scope-plugin-options: there is no config found');
}
const { allowedFiles, appSrcs, allowedPaths } = options;
const { allowedFiles, appSrcs, allowedPaths } = options || {};

const moduleScopePlugin = conf.resolve.plugins.find(
(plugin) => plugin.constructor && plugin.constructor.name && regexp.test(plugin.constructor.name),
);
Expand Down

0 comments on commit 16908a9

Please sign in to comment.