-
-
Notifications
You must be signed in to change notification settings - Fork 372
Feat/config types #1624
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
Merged
Merged
Feat/config types #1624
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3a4be08
feat: Adding types for config
rschristian 818f55c
docs: Updating docs with new config typings
rschristian 2038039
docs: Adding changeset
rschristian 4fd8b07
revert: JSDoc removal
rschristian fe2603b
fix: Correcting `getLoaders` types + docs
rschristian 2a6bb97
refactor: Revising types & JSDoc
rschristian 12e801c
refactor: Removing docs/webpack-helpers.md
rschristian 0b9ee56
docs: Updating ReadMe to point at wiki for webpack helpers
rschristian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'preact-cli': patch | ||
| --- | ||
|
|
||
| Added typings for users to use in their preact.config.js files |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| import webpack from 'webpack'; | ||
|
|
||
| type Rule = { | ||
| test: RegExp; | ||
| [key: string]: any; | ||
| }; | ||
|
|
||
| type RuleWrapper = { | ||
| index: number; | ||
| rule: Rule; | ||
| }; | ||
|
|
||
| type Loader = { | ||
| loader: string; | ||
| options: Record<string, any>; | ||
| }; | ||
|
|
||
| type LoadersWrapper = { | ||
| rule: { | ||
| test: RegExp; | ||
| [key: string]: any; | ||
| }; | ||
| ruleIndex: number; | ||
| loaders: string | (string | Loader)[]; | ||
| }; | ||
|
|
||
| type LoaderWrapper = { | ||
| rule: { | ||
| test: RegExp; | ||
| [key: string]: any; | ||
| }; | ||
| ruleIndex: number; | ||
| loader: string | Loader; | ||
| loaderIndex: number; | ||
| }; | ||
|
|
||
| type Plugin = Record<string, any>; | ||
|
|
||
| type PluginWrapper = { | ||
| index: number; | ||
| plugin: Plugin; | ||
| }; | ||
|
|
||
| /** | ||
| * Basic structure of config | ||
| */ | ||
| export type Config = { | ||
| resolve: { | ||
| modules: string[]; | ||
| extensions: string[]; | ||
| alias: string[]; | ||
| }; | ||
| module: { | ||
| rules: Rule[]; | ||
| }; | ||
| plugins: Plugin[]; | ||
| mode: 'production' | 'development'; | ||
| devtool: string | boolean; | ||
| output: { | ||
| filename: string; | ||
| chunkFilename: string; | ||
| publicPath: string; | ||
| [key: string]: any; | ||
| }; | ||
| devServer?: Record<string, any>; | ||
| [key: string]: any; | ||
| }; | ||
|
|
||
| /** | ||
| * Non-exhaustive list of environment conditions you may want | ||
| * to check for in your config | ||
| */ | ||
| export type Env = { | ||
| src: string; | ||
| dest: string; | ||
| esm: boolean; | ||
| sw: boolean; | ||
| dev: boolean; | ||
| production: boolean; | ||
| isProd: boolean; | ||
| ssr: boolean; | ||
| prerender: boolean; | ||
| [key: string]: any; | ||
| }; | ||
|
Comment on lines
+59
to
+70
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tried to cover the commonly used ones that I've seen. Did I miss any that should be added? |
||
|
|
||
| export type Helpers = { | ||
| /** | ||
| * Returns Webpack module used to create config | ||
| */ | ||
| webpack: typeof webpack; | ||
|
|
||
| /** | ||
| * Returns wrapper around all loaders from config | ||
| */ | ||
| getLoaders(config: Config): LoadersWrapper[]; | ||
|
|
||
| /** | ||
| * Returns wrapper around all loaders that match provided name | ||
| * | ||
| * @example helpers.getLoadersByName(config, 'babel-loader'); | ||
| */ | ||
| getLoadersByName(config: Config, name: string): LoaderWrapper[]; | ||
|
|
||
| /** | ||
| * Returns wrapper around all rules from config | ||
| */ | ||
| getRules(config: Config): RuleWrapper[]; | ||
|
|
||
| /** | ||
| * Returns wrapper around all rules that match provided file | ||
| * | ||
| * File is resolve relative to $PWD | ||
| * | ||
| * @example helpers.getRulesByMatchingFile(config, 'src/index.js'); | ||
| */ | ||
| getRulesByMatchingFile(config: Config, file: string): RuleWrapper[]; | ||
|
|
||
| /** | ||
| * Returns wrapper around all plugins from config | ||
| */ | ||
| getPlugins(config: Config): PluginWrapper[]; | ||
|
|
||
| /** | ||
| * Returns wrapper around all plugins that match provided name | ||
| * | ||
| * @example helpers.getPluginsByName(config, 'Critters'); | ||
| */ | ||
| getPluginsByName(config: Config, name: string): PluginWrapper[]; | ||
|
|
||
| /** | ||
| * Returns wrapper around all plugins that match provided type | ||
| * | ||
| * @example helpers.getPluginsByType(config, webpack.DefinePlugin); | ||
| */ | ||
| getPluginsByType(config: Config, type: any): PluginWrapper[]; | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.