From 999574700b8b3fb71ba63fd9da87087c32c5faa5 Mon Sep 17 00:00:00 2001 From: Rudi Yardley Date: Thu, 5 Mar 2020 07:00:36 +0700 Subject: [PATCH 1/3] Add new webpack package --- examples/first-demo/next.config.js | 2 +- packages/core/package.json | 2 -- packages/core/src/components/Form.tsx | 2 +- packages/webpack/.gitignore | 4 +++ packages/webpack/package.json | 40 +++++++++++++++++++++++++ packages/webpack/src/index.ts | 1 + packages/webpack/src/withBlitz.ts | 30 +++++++++++++++++++ packages/webpack/test/withBlitz.test.ts | 19 ++++++++++++ packages/webpack/tsconfig.json | 13 ++++++++ yarn.lock | 8 ++--- 10 files changed, 113 insertions(+), 8 deletions(-) create mode 100644 packages/webpack/.gitignore create mode 100644 packages/webpack/package.json create mode 100644 packages/webpack/src/index.ts create mode 100644 packages/webpack/src/withBlitz.ts create mode 100644 packages/webpack/test/withBlitz.test.ts create mode 100644 packages/webpack/tsconfig.json diff --git a/examples/first-demo/next.config.js b/examples/first-demo/next.config.js index 9b44f21b81..d993c9142e 100644 --- a/examples/first-demo/next.config.js +++ b/examples/first-demo/next.config.js @@ -1,3 +1,3 @@ -const {withBlitz} = require('@blitzjs/core') +const {withBlitz} = require('@blitzjs/webpack') module.exports = withBlitz({}) diff --git a/packages/core/package.json b/packages/core/package.json index 1f10c666b8..fdaa3d6e33 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -55,8 +55,6 @@ "@testing-library/react": "9.4.1", "@types/react": "16.9.23", "next": "9.2.3-canary.8", - "next-compose-plugins": "2.2.0", - "next-transpile-modules": "3.0.2", "null-loader": "3.0.0", "prisma2": "2.0.0-preview022" }, diff --git a/packages/core/src/components/Form.tsx b/packages/core/src/components/Form.tsx index ba18e37bc7..25bb09b1df 100644 --- a/packages/core/src/components/Form.tsx +++ b/packages/core/src/components/Form.tsx @@ -9,7 +9,7 @@ export default function({children, action, method, ...props}: {[index: string]: // Warm the lamba // TODO: Only do this once per route fetch(action, {method: 'HEAD'}) - }, []) + }, [action]) return (
= {}) { + const plugins = [] + if (process.env.NODE_ENV === 'development') { + // This is needed during monorepo development so that examples auto reload when packages change + plugins.push(withTM) + } + + return withPlugins( + plugins, + Object.assign({}, nextConfig, { + webpack(config: any, options: Record) { + if (!options.isServer) { + // Ensure prisma client is not included in the client bundle + config.module.rules.push({ + test: /@prisma\/client/, + use: 'null-loader', + }) + } + + if (typeof nextConfig.webpack === 'function') { + return nextConfig.webpack(config, options) + } + return config + }, + }), + ) +} diff --git a/packages/webpack/test/withBlitz.test.ts b/packages/webpack/test/withBlitz.test.ts new file mode 100644 index 0000000000..5eb74723b1 --- /dev/null +++ b/packages/webpack/test/withBlitz.test.ts @@ -0,0 +1,19 @@ +import {withBlitz} from '../src' + +describe('withBlitz', () => { + it('alters the webpack config as expeted', () => { + const nextConfigFn = withBlitz({}) + const newNext = nextConfigFn('', {defaultConfig: {}}) + const newWebpack = newNext.webpack({module: {rules: []}}, {}) + expect(newWebpack).toEqual({ + module: { + rules: [ + { + test: /@prisma\/client/, + use: 'null-loader', + }, + ], + }, + }) + }) +}) diff --git a/packages/webpack/tsconfig.json b/packages/webpack/tsconfig.json new file mode 100644 index 0000000000..26c99810c3 --- /dev/null +++ b/packages/webpack/tsconfig.json @@ -0,0 +1,13 @@ +{ + "extends": "../../tsconfig.json", + "include": ["src", "test"], + "exclude": ["node_modules"], + "compilerOptions": { + "baseUrl": "./", + "declarationDir": "./dist", + "downlevelIteration": true, + "paths": { + "*": ["src/*", "node_modules/*"] + } + } +} diff --git a/yarn.lock b/yarn.lock index 40d0bc941e..edc663da16 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10307,7 +10307,7 @@ neo-async@^2.5.0, neo-async@^2.6.0, neo-async@^2.6.1: resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.1.tgz#ac27ada66167fa8849a6addd837f6b189ad2081c" integrity sha512-iyam8fBuCUpWeKPGpaNMetEocMt364qkCsfL9JuhjXX6dRnguRVOfk2GZaDpPjcOKiiXCPINZC1GczQ7iTq3Zw== -next-compose-plugins@2.2.0: +next-compose-plugins@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/next-compose-plugins/-/next-compose-plugins-2.2.0.tgz#95cd8eb40ab0652070d76572fb648354191628b0" integrity sha512-ChUlpT9tWfJ7YxqGw/WQ2T1gf8EeX93n1XqeQw0lkvGa7seszahvF4eOZUJoq7Hetsbzg4UHVnPoCXfXTyQR3g== @@ -10317,7 +10317,7 @@ next-tick@~1.0.0: resolved "https://registry.yarnpkg.com/next-tick/-/next-tick-1.0.0.tgz#ca86d1fe8828169b0120208e3dc8424b9db8342c" integrity sha1-yobR/ogoFpsBICCOPchCS524NCw= -next-transpile-modules@3.0.2: +next-transpile-modules@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/next-transpile-modules/-/next-transpile-modules-3.0.2.tgz#b289698d453bb7346fd768da171b53a740bfe436" integrity sha512-w3WsyxvkJ3ws16InHwXhlDaOyG6Peo4co9U2sVBMePwEDo9r3SsbzX7p43sLUTYbpuA2t9iwJoCXkj/4BuD3Qw== @@ -14652,7 +14652,7 @@ tslib@1.10.0: resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a" integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ== -tslib@^1, tslib@^1.10.0, tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3: +tslib@^1, tslib@^1.10.0, tslib@^1.11.1, tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3: version "1.11.1" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.11.1.tgz#eb15d128827fbee2841549e171f45ed338ac7e35" integrity sha512-aZW88SY8kQbU7gpV19lN24LtXh/yD4ZZg6qieAJDDg+YBsJcSmLGK9QpnUjAKVG/xefmvJGd1WUmfpT/g6AJGA== @@ -14740,7 +14740,7 @@ typescript@3.8.2: resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.8.2.tgz#91d6868aaead7da74f493c553aeff76c0c0b1d5a" integrity sha512-EgOVgL/4xfVrCMbhYKUQTdF37SQn4Iw73H5BgCrF1Abdun7Kwy/QZsE/ssAy0y4LxBbvua3PIbFsbRczWWnDdQ== -typescript@^3.7.3, typescript@^3.7.5: +typescript@^3.7.3, typescript@^3.7.5, typescript@^3.8.3: version "3.8.3" resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.8.3.tgz#409eb8544ea0335711205869ec458ab109ee1061" integrity sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w== From cc0b19be6348382c4fd6c6ed82fb9066eb81807a Mon Sep 17 00:00:00 2001 From: Rudi Yardley Date: Thu, 5 Mar 2020 07:20:10 +0700 Subject: [PATCH 2/3] Delete webpack files from core --- packages/core/src/index.ts | 1 - packages/core/src/webpack/index.ts | 30 ------------------------------ 2 files changed, 31 deletions(-) delete mode 100644 packages/core/src/webpack/index.ts diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 7f2de20e0e..87693e5351 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,3 +1,2 @@ export * from './components' export * from './controller' -export {default as withBlitz} from './webpack' diff --git a/packages/core/src/webpack/index.ts b/packages/core/src/webpack/index.ts deleted file mode 100644 index b5fcac6cd7..0000000000 --- a/packages/core/src/webpack/index.ts +++ /dev/null @@ -1,30 +0,0 @@ -const withPlugins = require('next-compose-plugins') -const withTM = require('next-transpile-modules')(['@blitzjs/core']) - -export default function(nextConfig: Record = {}) { - const plugins = [] - if (process.env.NODE_ENV === 'development') { - // This is needed during monorepo development so that examples auto reload when packages change - plugins.push(withTM) - } - - return withPlugins( - plugins, - Object.assign({}, nextConfig, { - webpack(config: any, options: Record) { - if (!options.isServer) { - // Ensure prisma client is not included in the client bundle - config.module.rules.push({ - test: /@prisma\/client/, - use: 'null-loader', - }) - } - - if (typeof nextConfig.webpack === 'function') { - return nextConfig.webpack(config, options) - } - return config - }, - }), - ) -} From dacfb84f79fd2411179b3f50e66e1fcd6663ec93 Mon Sep 17 00:00:00 2001 From: Rudi Yardley Date: Thu, 5 Mar 2020 08:52:50 +0700 Subject: [PATCH 3/3] Pin dependencies --- packages/webpack/package.json | 4 ++-- yarn.lock | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/webpack/package.json b/packages/webpack/package.json index 65d5ba32e8..28029ef832 100644 --- a/packages/webpack/package.json +++ b/packages/webpack/package.json @@ -34,7 +34,7 @@ "typescript": "^3.8.3" }, "dependencies": { - "next-compose-plugins": "^2.2.0", - "next-transpile-modules": "^3.0.2" + "next-compose-plugins": "2.2.0", + "next-transpile-modules": "3.0.2" } } diff --git a/yarn.lock b/yarn.lock index edc663da16..0bdf051ea5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10307,7 +10307,7 @@ neo-async@^2.5.0, neo-async@^2.6.0, neo-async@^2.6.1: resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.1.tgz#ac27ada66167fa8849a6addd837f6b189ad2081c" integrity sha512-iyam8fBuCUpWeKPGpaNMetEocMt364qkCsfL9JuhjXX6dRnguRVOfk2GZaDpPjcOKiiXCPINZC1GczQ7iTq3Zw== -next-compose-plugins@^2.2.0: +next-compose-plugins@2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/next-compose-plugins/-/next-compose-plugins-2.2.0.tgz#95cd8eb40ab0652070d76572fb648354191628b0" integrity sha512-ChUlpT9tWfJ7YxqGw/WQ2T1gf8EeX93n1XqeQw0lkvGa7seszahvF4eOZUJoq7Hetsbzg4UHVnPoCXfXTyQR3g== @@ -10317,7 +10317,7 @@ next-tick@~1.0.0: resolved "https://registry.yarnpkg.com/next-tick/-/next-tick-1.0.0.tgz#ca86d1fe8828169b0120208e3dc8424b9db8342c" integrity sha1-yobR/ogoFpsBICCOPchCS524NCw= -next-transpile-modules@^3.0.2: +next-transpile-modules@3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/next-transpile-modules/-/next-transpile-modules-3.0.2.tgz#b289698d453bb7346fd768da171b53a740bfe436" integrity sha512-w3WsyxvkJ3ws16InHwXhlDaOyG6Peo4co9U2sVBMePwEDo9r3SsbzX7p43sLUTYbpuA2t9iwJoCXkj/4BuD3Qw==