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

chore(gatsby): migrate webpack-plugins to TypeScript #22378

Merged
merged 1 commit into from
Mar 18, 2020
Merged
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
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// @flow
import webpack, { Plugin } from "webpack"

const webpack = require(`webpack`)

const plugin = (name, optimize) => {
const Plugin = (optimize ? webpack.optimize : webpack)[name]
return (...args: any) => new Plugin(...args)
const plugin = (name: string, optimize?: boolean): Plugin => {
const WebpackPlugin = (optimize ? webpack.optimize : webpack)[name]
return (...args: any): Plugin => new WebpackPlugin(...args)
}

const plugins = {
export const builtinPlugins = {
normalModuleReplacement: plugin(`NormalModuleReplacementPlugin`),
contextReplacement: plugin(`ContextReplacementPlugin`),
ignore: plugin(`IgnorePlugin`),
Expand Down Expand Up @@ -53,5 +51,3 @@ const plugins = {
occurrenceOrder: plugin(`OccurrenceOrderPlugin`, true),
moduleConcatenation: plugin(`ModuleConcatenationPlugin`, true),
}

module.exports = plugins
12 changes: 6 additions & 6 deletions packages/gatsby/src/utils/webpack-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const isWsl = require(`is-wsl`)
const GatsbyWebpackStatsExtractor = require(`./gatsby-webpack-stats-extractor`)
const GatsbyWebpackEslintGraphqlSchemaReload = require(`./gatsby-webpack-eslint-graphql-schema-reload-plugin`)

const builtinPlugins = require(`./webpack-plugins`)
import { builtinPlugins } from "./webpack-plugins"
const eslintConfig = require(`./eslint-config`)

type LoaderSpec = string | { loader: string, options?: Object }
Expand Down Expand Up @@ -132,15 +132,15 @@ module.exports = async ({
const makeExternalOnly = (original: RuleFactory<*>) => (
options = {}
): Rule => {
let rule = original(options)
const rule = original(options)
rule.include = vendorRegex
return rule
}

const makeInternalOnly = (original: RuleFactory<*>) => (
options = {}
): Rule => {
let rule = original(options)
const rule = original(options)
rule.exclude = vendorRegex
return rule
}
Expand Down Expand Up @@ -307,7 +307,7 @@ module.exports = async ({
* and packages that depend on `gatsby`
*/
{
let js = ({ modulesThatUseGatsby = [], ...options } = {}) => {
const js = ({ modulesThatUseGatsby = [], ...options } = {}) => {
return {
test: /\.(js|mjs|jsx)$/,
include: modulePath => {
Expand Down Expand Up @@ -342,7 +342,7 @@ module.exports = async ({
* Excludes modules that use Gatsby since the `rules.js` already transpiles those
*/
{
let dependencies = ({ modulesThatUseGatsby = [] } = {}) => {
const dependencies = ({ modulesThatUseGatsby = [] } = {}) => {
const jsOptions = {
babelrc: false,
configFile: false,
Expand Down Expand Up @@ -391,7 +391,7 @@ module.exports = async ({
}

{
let eslint = schema => {
const eslint = schema => {
return {
enforce: `pre`,
test: /\.jsx?$/,
Expand Down