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

Fix rollup.js issues in nextjs-apollo-config #160

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/nextjs-apollo-client/.gitignore
@@ -1 +1,5 @@
dist
dist
# Ignore meta file generated by incremental typescript compilation
*.tsbuildinfo
.rollup.cache
bundle-analysis.html
28 changes: 23 additions & 5 deletions packages/nextjs-apollo-client/package.json
Expand Up @@ -4,20 +4,32 @@
"files": [
"dist"
],
"main": "dist/index.js",
"module": "src/index.ts",
"types": "dist/types/index.d.ts",
"main": "./dist/index.cjs.js",
"module": "./dist/index.es.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.es.js",
"require": "./dist/index.cjs.js"
}
},
"license": "MIT",
"private": true,
"scripts": {
"prebuild": "rimraf dist",
"build": "tsc",
"dev": "tsc -w",
"build": "rollup -c",
"dev": "rollup -c -w",
"analyze": "ANALYZE=true yarn build",
"generate::possibleTypes": "node scripts/generatePossibleTypes.js"
},
"devDependencies": {
"@apollo/client": "^3.5.8",
"@republik/eslint-config-frontend": "*",
"@rollup/plugin-babel": "^5.3.1",
"@rollup/plugin-commonjs": "^22.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.3.0",
"@rollup/plugin-typescript": "8.3.3",
"@types/node": "^17.0.41",
"@types/react": "^17.0.39",
"@types/react-dom": "^17.0.17",
Expand All @@ -27,6 +39,12 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"rimraf": "^3.0.2",
"rollup": "^2.75.6",
"rollup-plugin-bundle-size": "^1.0.3",
"rollup-plugin-dts": "^4.2.2",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-visualizer": "^5.6.0",
"typescript": "^4.7.2",
"uuid": "^3.4.0"
},
Expand Down
50 changes: 50 additions & 0 deletions packages/nextjs-apollo-client/rollup.config.js
@@ -0,0 +1,50 @@
import nodeResolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import peerDepsExternal from 'rollup-plugin-peer-deps-external'
import dts from 'rollup-plugin-dts'
import typescript from '@rollup/plugin-typescript'
import json from '@rollup/plugin-json'
import { terser } from 'rollup-plugin-terser'
import visualizer from 'rollup-plugin-visualizer'
import bundleSize from 'rollup-plugin-bundle-size'
import path from 'path'

const pkgJSON = require('./package.json')

export default [
{
input: 'src/index.ts',
output: [
{
file: pkgJSON.module,
format: 'esm',
},
{
file: pkgJSON.main,
format: 'cjs',
},
],
plugins: [
peerDepsExternal(),
nodeResolve(),
json(),
commonjs(),
typescript({
tsconfig: './tsconfig.json',
outputToFilesystem: true,
}),
terser(),
bundleSize(),
process.env.ANALYZE === 'true' &&
visualizer(() => ({
filename: path.join(__dirname, 'bundle-analysis.html'),
})),
],
external: Object.keys(pkgJSON.peerDependencies || {}),
},
{
input: 'dist/types/index.d.ts',
output: [{ file: 'dist/index.d.ts', format: 'esm' }],
plugins: [nodeResolve({ preferBuiltins: true }), dts()],
},
]
12 changes: 12 additions & 0 deletions packages/nextjs-apollo-client/src/apollo/safeJSON.js
@@ -0,0 +1,12 @@
export const parseJSONObject = (json) => {
let object
try {
object = JSON.parse(json)
} catch (error) {}
// handle null and undefined
// - remember that typeof null === 'object'
if (!object) {
object = {}
}
return object
}
16 changes: 6 additions & 10 deletions packages/nextjs-apollo-client/tsconfig.json
@@ -1,7 +1,6 @@
{
"compilerOptions": {
"allowJs": true,
"target": "es5",
"target": "ES5",
"lib": [
"dom",
"dom.iterable",
Expand All @@ -11,22 +10,19 @@
"strict": false,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"module": "ESNext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"incremental": true,
"allowSyntheticDefaultImports": true,
"outDir": "./dist",
"module": "commonjs",
"noEmit": false,
"sourceMap": true,
"declaration": true,
"declarationDir": "./dist/types",
"declarationMap": true
"declarationDir": "types",
"rootDir": "src"
},
"include": [
"src"
"src/**/*.ts",
"src/**/*.tsx"
],
"exclude": [
"node_modules",
Expand Down