-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.ts
44 lines (39 loc) · 1.51 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import PrismaClientReloaderWebpackPlugin from './webpack-plugin'
const PATH_DELIMITER = '[\\\\/]' // match 2 antislashes or one slash
/**
* On Windows, the Regex won't match as Webpack tries to resolve the
* paths of the modules. So we need to check for \\ and /
*/
// @ts-ignore
const safePath = (module) => module.split(/[\\\/]/g).join(PATH_DELIMITER)
/**
* Actual Next.js plugin
*/
const withPrismaPlugin = (nextConfig = {}) => (
phase: 'phase-export' | 'phase-production-build' | 'phase-production-server' | 'phase-development-server',
thing: any
) => {
if (phase === 'phase-development-server') {
return Object.assign({}, nextConfig, {
webpack(config: any, options: any) {
const ignore = ['.prisma/client', '@prisma/client']
// const includes = ignore.map(module => (new RegExp(`${module}(?!.*node_modules)`)));
const excludes = [new RegExp(`node_modules(?!/(${ignore.join('|')})(?!.*node_modules))`)]
const ignored = config.watchOptions.ignored
.filter((ignored: string) => ignored !== '**/node_modules/**')
.concat(excludes)
return Object.assign(config, {
plugins: [...config.plugins, new PrismaClientReloaderWebpackPlugin()],
watchOptions: {
...config.watchOptions,
ignored,
},
})
},
})
}
let internalConfigObj = typeof nextConfig === 'function' ? nextConfig(phase, thing) : nextConfig
return internalConfigObj
}
module.exports = withPrismaPlugin
export default withPrismaPlugin