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

[WIP]: chore(gatsby): migrate webpack utils to TypeScript #22381

Merged
merged 15 commits into from
Mar 20, 2020
Merged
Prev Previous commit
Next Next commit
fix migration of webpack-utils
  • Loading branch information
sasurau4 committed Mar 18, 2020
commit 5469cc3a6c91c8a31578ee324148dc37619f171c
7 changes: 5 additions & 2 deletions packages/gatsby/src/utils/webpack-plugins.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import webpack, { Plugin } from "webpack"
import webpack, { Plugin, IgnorePlugin, WatchIgnorePlugin } from "webpack"

const plugin = (name: string, optimize?: boolean): Plugin => {
const plugin = (
name: string,
optimize?: boolean
): ((...args: any) => Plugin) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ha good catch. Thanks for fixing!

const WebpackPlugin = (optimize ? webpack.optimize : webpack)[name]
return (...args: any): Plugin => new WebpackPlugin(...args)
}
Expand Down
29 changes: 13 additions & 16 deletions packages/gatsby/src/utils/webpack-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,17 @@ export interface IRuleUtils {
eslint: RuleFactory
}

export type PluginUtils = BuiltinPlugins & {
extractText: PluginFactory
uglify: PluginFactory
moment: PluginFactory
extractStats: PluginFactory
}
export type PluginUtils = BuiltinPlugins &
Partial<{
extractText: PluginFactory
uglify: PluginFactory
moment: PluginFactory
extractStats: PluginFactory
minifyJs: PluginFactory
minifyCss: PluginFactory
fastRefresh: PluginFactory
eslintGraphqlSchemaReload: PluginFactory
}>

/**
* webpack atoms namespace
Expand Down Expand Up @@ -130,23 +135,15 @@ export const createUtils = async ({

const makeExternalOnly = (original: RuleFactory) => (
options = {}
<<<<<<< HEAD:packages/gatsby/src/utils/webpack-utils.ts
): RuleSetRule => {
=======
): Rule => {
>>>>>>> 7095e418b30989e671899aee68fe25afca82a89c:packages/gatsby/src/utils/webpack-utils.js
const rule = original(options)
rule.include = vendorRegex
return rule
}

const makeInternalOnly = (original: RuleFactory) => (
options = {}
<<<<<<< HEAD:packages/gatsby/src/utils/webpack-utils.ts
): RuleSetRule => {
=======
): Rule => {
>>>>>>> 7095e418b30989e671899aee68fe25afca82a89c:packages/gatsby/src/utils/webpack-utils.js
const rule = original(options)
rule.exclude = vendorRegex
return rule
Expand Down Expand Up @@ -530,7 +527,7 @@ export const createUtils = async ({
/**
* Plugins
*/
const plugins = { ...builtinPlugins }
const plugins: PluginUtils = { ...builtinPlugins }

/**
* Minify JavaScript code without regard for IE8. Attempts
Expand All @@ -539,7 +536,7 @@ export const createUtils = async ({
plugins.minifyJs = ({
terserOptions,
...options
}: { terserOptions?: TerserPlugin.TerserPluginOptions } = {}): RuleSetRule =>
}: { terserOptions?: TerserPlugin.TerserPluginOptions } = {}): Plugin =>
new TerserPlugin({
cache: true,
// We can't use parallel in WSL because of https://github.com/gatsbyjs/gatsby/issues/6540
Expand Down