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

Next.js: upgrade next-transpile-modules #19

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 2 additions & 7 deletions next/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

# FullCalendar Next.js Example

Getting FullCalendar to work with [Next.js](https://nextjs.org/) requires a bit of configuration. See below.


## Installation

```bash
Expand All @@ -12,7 +10,6 @@ cd fullcalendar-example-projects/next
npm install
```


## Build Commands

```
Expand All @@ -22,13 +19,11 @@ npm run start # run the production build
npm run clean # clear all built files
```


## Workarounds Explained

1. Install [next-transpile-modules](https://www.npmjs.com/package/next-transpile-modules) to process FullCalendar's ES modules. See [next.config.js](next.config.js). If you don't like this, [vote to give Next ESM support for third-party packages](https://github.com/vercel/next.js/issues/706).
2. Configure Babel to ignore imports of CSS files, which FullCalendar uses to include styles. Uses the [babel-plugin-transform-require-ignore](https://www.npmjs.com/package/babel-plugin-transform-require-ignore) plugin. See [babel.config.js](babel.config.js)
3. In [_app.jsx](pages/_app.jsx), include FullCalendar's global stylesheets manually...

2. Configure Babel to ignore imports of CSS files, which FullCalendar uses to include styles. Uses the [babel-plugin-transform-import-ignore](https://www.npmjs.com/package/babel-plugin-transform-import-ignore) plugin. See [babel.config.js](babel.config.js)
3. In [\_app.jsx](pages/_app.jsx), include FullCalendar's global stylesheets manually...

## FullCalendar Stylesheets

Expand Down
25 changes: 9 additions & 16 deletions next/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@

module.exports = {

presets: [
'@babel/preset-react' // necessary for all .jsx files
],
presets: ['next/babel'],

// fullcalendar attempts to import its own CSS files, but next.js does not allow this.
// throw away these statements before they arrive at next.js,
// but you'll need to import them manually in pages/_app.jsx.
// will also work for any other 3rd-party packages that attempt to do this.
overrides: [{
include: [
'./node_modules'
],
plugins: [
['babel-plugin-transform-require-ignore', {
extensions: ['.css']
}]
]
}]

overrides: [
{
include: ['./node_modules'],
plugins: [
['babel-plugin-transform-import-ignore', { patterns: ['.css'] }]
]
}
]
}
10 changes: 8 additions & 2 deletions next/next.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@

// for transpiling all ESM @fullcalendar/* packages
// also, for piping fullcalendar thru babel (to learn why, see babel.config.js)

const withTM = require('next-transpile-modules')([
'@fullcalendar'
// Need to specify all @fullcalendar modules separately
// with next-transpile-modules^6.x …

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above this PR is good but I'd refer folks to the next-transpile-modules compatibility table as well.

'@fullcalendar/core',
'@fullcalendar/react',
'@fullcalendar/common',
'@fullcalendar/daygrid',
'@fullcalendar/timegrid'
])

module.exports = withTM({
Expand Down
18 changes: 10 additions & 8 deletions next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@
"dependencies": {
"@babel/core": "^7.12.3",
"@babel/preset-react": "^7.10.4",
"@fullcalendar/common": "^5.4.0",
"@fullcalendar/daygrid": "^5.4.0",
"@fullcalendar/interaction": "^5.4.0",
"@fullcalendar/react": "^5.4.0",
"@fullcalendar/timegrid": "^5.4.0",
"babel-plugin-transform-require-ignore": "^0.1.1",
"next": "^10.0.1",
"next-transpile-modules": "^4.1.0",
"@fullcalendar/core": "^5.5.1",
"@fullcalendar/daygrid": "^5.5.0",
"@fullcalendar/interaction": "^5.5.0",
"@fullcalendar/react": "^5.5.0",
"@fullcalendar/timegrid": "^5.5.1",
"next": "^10.0.8",
"next-transpile-modules": "^6.3.0",
"react": "^17.0.1",
"react-dom": "^17.0.1"
},
"devDependencies": {
"babel-plugin-transform-import-ignore": "^1.1.0"
}
}
2 changes: 0 additions & 2 deletions next/pages/_app.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import React from 'react'

import '@fullcalendar/common/main.css'
import '@fullcalendar/daygrid/main.css'
import '@fullcalendar/timegrid/main.css'
Expand Down
25 changes: 13 additions & 12 deletions next/pages/index.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import React from 'react'
import FullCalendar from '@fullcalendar/react'
import interactionPlugin from '@fullcalendar/interaction'
import timeGridPlugin from '@fullcalendar/timegrid'

export default () => (
<FullCalendar
plugins={[interactionPlugin, timeGridPlugin]}
initialView='timeGridWeek'
nowIndicator={true}
editable={true}
initialEvents={[
{ title: 'nice event', start: new Date() }
]}
/>
)
const Page = () => {
return (
<FullCalendar
plugins={[interactionPlugin, timeGridPlugin]}
initialView="timeGridWeek"
nowIndicator={true}
editable={true}
initialEvents={[{ title: 'nice event', start: new Date() }]}
/>
)
}

export default Page
Loading