Skip to content
Open
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
46 changes: 30 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,44 @@
module.exports = (nextConfig = {}) => {
// ts-check

/**
* @typedef {Object} Options
* @property {Array.<string|RegExp>} [include] - Additional directories to include
*/

/**
* @fileoverview Next.js plugin for loading GraphQL files
* @param {import('next').NextConfig} nextConfig
* @param {Options} [opts]
* @return {import('next').NextConfig}
*/
module.exports = (nextConfig = {}, opts = {}) => {
return Object.assign({}, nextConfig, {
webpack(config, options) {
if (!options.defaultLoaders) {
throw new Error(
'This plugin is not compatible with Next.js versions below 5.0.0 https://err.sh/next-plugins/upgrade'
)
"This plugin is not compatible with Next.js versions below 5.0.0 https://err.sh/next-plugins/upgrade"
);
}

const { dir } = options
const { dir } = options;
const { include, exclude } = opts || {};

config.module.rules.push({
test: /\.(graphql|gql)$/,
include: [dir],
exclude: /node_modules/,
include: [dir].concat(include || []),
exclude: [/node_modules/].concat(exclude || []),
use: [
{
loader: 'graphql-tag/loader'
}
]
})
loader: "graphql-tag/loader",
},
],
});

if (typeof nextConfig.webpack === 'function') {
return nextConfig.webpack(config, options)
if (typeof nextConfig.webpack === "function") {
return nextConfig.webpack(config, options);
}

return config
}
})
}
return config;
},
});
};