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

[WIP] rollup and ESM export #1858

Closed
wants to merge 12 commits into from

Conversation

LoicMahieu
Copy link
Contributor

1. Summary

It's a quite big PR for my first contribution. I'm sorry, I would have preferred to find something easier to do at first. I tried something simple, it's in the garage... I could not develop it on top of the actual build system due to performance.

There is some problem in the current build implementation:

  • All modules (except netlify-cms) produces a UMD build which, I think, is never used by anyone. (Maybe there is a case for import manually a widget or something else ?)
  • netlify-cms module have an "hacky" import. Since we don't want to bundle once again a UMD bundle from other UMD bundles, it imports directly /src.
  • netlify-cms have a bunch of dependencies that are not used in production, since every dependencies are bundled.
  • Build is slow. In my machine, I have waited more than 5 minutes for a complete build with all CPU to the top!

Important changes:

  • Switch to rollup instead of webpack for all modules (except netlify-cms). It only produces a ESM build.
  • netlify-cms still build an UMD package from the ESM with webpack.
  • icons: switch to rollup-plugin-react-svg for SVG to React transformation. It does not seem to change much.
  • Remove alias and module-resolver. It was initially proposed in PR netlify-cms-core: remove alias and module-resolver #1847. I did that because I found difficulties to implement it with Rollup and...... since I don't like it much... 😚 But it should be possible to use it. If you want to see them come back, yell at me and I'll do what's necessary.

Advantages:

Fixes issues:

Breaking changes

  • All modules (except netlify-cms) will not exports a main file but only an module file.
    It does not introduce any breaking change on netlify-cms.
    I don't know if they are used separately/directly.
  • I don't see any other breaking change 😅

2. Test plan

CI should confirm that build works. Tested on my machine, build and develop works well!

3. A picture of a cute animal

As big as this PR!

huge-dogs-puppies-06

Some advantages to remove aliases:
- Better integration with code editors (VSCode in mind)
- Easier to move to another bundler
@verythorough
Copy link
Contributor

verythorough commented Nov 6, 2018

Deploy preview for netlify-cms-www ready!

Built with commit 9292cb5

https://deploy-preview-1858--netlify-cms-www.netlify.com

@verythorough
Copy link
Contributor

verythorough commented Nov 6, 2018

Deploy preview for cms-demo ready!

Built with commit 9292cb5

https://deploy-preview-1858--cms-demo.netlify.com

@LoicMahieu
Copy link
Contributor Author

LoicMahieu commented Nov 6, 2018

Current problems:

  • Rollup watch have an issue (I think rollup fails to resolve entry file when using --watch, seemingly at random rollup/rollup#982).
    When I open a random file, just hit cmd+s and it produces this kind of error:
    no such file or directory, open 'react'.
    (It is not always react)
    Keep investigating....

  • netlify-cms: show this warning: "export 'BitBucketBackend' was not found in 'netlify-cms-backend-bitbucket'
    I don't know yet why this warning is there but BitBucketBackend is well exported!

My first wish at this time is to receive your opinion about this implementation and knowing if I could go further.
I want to invest my time and that of my team on this fantastic project!

Thanks for your attention!

@erquhart
Copy link
Contributor

erquhart commented Nov 6, 2018

First of all, thank you! This is awesome work in a critical area of need for the project!! 👏👏

Whenever a massive changeset comes through, it's good to slim down where we can. I'd really like to see removal of module-resolver dropped from this PR, as it adds a lot of noise. Hopefully we can get rollup to play nice with it.

Checking it out locally now.

This reverts commit 376ded3.

# Conflicts:
#	packages/netlify-cms-core/babel.config.js
#	packages/netlify-cms-core/src/reducers/auth.js
For an unkonwn reason, some aliased import does not work in Rollup like Webpack.
For example, `import ‘Redux’` results in `require(‘./redux/index.js’)` in the ESM bundle and it is not bundled.
@LoicMahieu
Copy link
Contributor Author

Hi @erquhart
Thank you for your interest!

I agree that removal of module-resolver adds a lot of noise. Unfortunately, this plugin does not deal well with rollup.
I reverted the commit (I'll rebase this branch later) and I had to modify each "implicit index.js import" for an "explicitly import", exemple:

- import { getAsset } from 'Reducers';
+ import { getAsset } from 'Reducers/index';

Otherwise, rollup output contains:

import { getAsset } from "./redux/index";

In that case, Rollup does not find the module and left the import into the bundle...
Since import explicitly /index is really ugly, I don't think this branch should be merged as is.

I tried to solves aliases from Rollup with plugin:

I need to investigate more about it but... I am convicted that aliases are not necessary 😬

@erquhart
Copy link
Contributor

erquhart commented Nov 7, 2018

I've restructured this entire codebase twice in the last twelve months; relative imports were a ridiculous pain to deal with. Let's see if we can find a way to make aliases work.

@erquhart
Copy link
Contributor

erquhart commented Nov 7, 2018

This comment by Rich Harris is right on - adding /index is fine, let's just do that.

@Benaiah
Copy link
Contributor

Benaiah commented Nov 7, 2018

I'm also fine with just importing using index; it's not much more verbose and makes it a bit clearer for people who aren't already aware that index.js is the default entry point for a folder.

@LoicMahieu
Copy link
Contributor Author

Yep okay let's keep the /index.
I tried to use rollup-plugin-alias but it does not support root as babel-plugin-module-resolver. So paths like UI, UI/FooComponent, EditorWidgets etc... does not work.
Anyway, it works well with module-resolver.

@LoicMahieu
Copy link
Contributor Author

I remove the WIP. In my use cases, it works well. Need your feedback ;) Thanks!

@LoicMahieu LoicMahieu changed the title WIP: rollup and ESM export rollup and ESM export Nov 9, 2018
@erquhart
Copy link
Contributor

Off today but I'll dig into this tomorrow 👍

Copy link
Contributor

@erquhart erquhart left a comment

Choose a reason for hiding this comment

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

Just a couple of small changes (plus merge conflict resolution) and this is good to merge - awesome work @LoicMahieu, this is a clutch PR!! 👏👏

const pkg = require('./package.json');
const { plugins } = require('../../scripts/webpack');
const coreWebpackConfig = require('../netlify-cms-core/webpack.config.js');
const pkg = require(path.join(process.cwd(), 'package.json'));
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd opt for __dirname instead of process.cwd() here, in case the cli is run from somewhere other than root.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pkg here should be the specific package, not the root. The logic does not change from the current version.

@erquhart
Copy link
Contributor

Update: looks like our UMD build went from ~2MB to ~4MB. We'll have to find a way to address that before merging.

@alexandernanberg
Copy link
Contributor

I've restructured this entire codebase twice in the last twelve months; relative imports were a ridiculous pain to deal with. Let's see if we can find a way to make aliases work.

Just curious what was a pain with relative paths? In my experience it's the other way around 😛

@erquhart
Copy link
Contributor

When you move a file to a different level of nesting, all relative imports break. When you move 80 files to a different level of nesting, your sanity breaks.

Sent with GitHawk

@alexandernanberg
Copy link
Contributor

@LoicMahieu Do you have enough time to get this through to the finish line? If not I could have a look and try to fix the remaining stuff 😄

@erquhart
Copy link
Contributor

GitHub needs a 💪reaction. You're killing it @alexandernanberg.

@LoicMahieu
Copy link
Contributor Author

Hi @alexandernanberg
Any help is welcome 😉 I fixed the review above. Indeed I don't have many time to devote 😣
The problems that are still there:

* official/master: (42 commits)
  chore: improve publish scripts
  Publish
  chore: test before publishing
  chore(netlify-cms-core): upgrade react-dnd to 7.x (decaporg#1922)
  chore(netlify-cms-widget-text): upgrade to react-textarea-autosize 7.x (decaporg#1921)
  chore(netlify-cms-core): upgrade to react-waypoint 8.x (decaporg#1920)
  fix(backend): use singular label in custom commit message (decaporg#1917)
  docs: add GAE-specific oAuth client (decaporg#1918)
  fix(netlify-cms-widget-text): set correct font family (decaporg#1916)
  chore(netlify-cms-core): upgrade redux and related dependencies (decaporg#1914)
  chore(dependencies): bump npm-run-all (decaporg#1913)
  fix(netlify-cms-core): fix identifier field validation (decaporg#1907)
  docs: improve widget custom validation sample (decaporg#1911)
  improvement(backends): changes for registerBackend compatibility (decaporg#1880)
  fix(netlify-cms-core): fix prop-types warnings (decaporg#1906)
  fix(a11y): correct label "for" references to fields (decaporg#1904)
  improvement(netlify-cms-core): wrap navigations in lists for better a11y (decaporg#1903)
  fix(netlify-cms-widget-markdown): add missing border radius on toolbar (decaporg#1905)
  fix(netlify-cms-core): remove double focusable elements on profile menu button (decaporg#1900)
  fix(config): remove identifier field validation (decaporg#1882)
  ...
@erquhart erquhart changed the title rollup and ESM export [WIP] rollup and ESM export Dec 3, 2018
* official/master:
  update release ticker
  Publish
  feat: add cloudinary support (decaporg#1932)
  fix(netlify-cms-core): duplicate key warning (decaporg#1930)
  Update image.md (decaporg#1923)
  chore(netlify-cms-core): upgrade react-frame-component to 4.x (decaporg#1925)
  chore(netlify-cms-core): upgrade gray-matter to 4.x (decaporg#1924)
  feat(netlify-cms-widget-select): add support for multiple selection (decaporg#1901)

# Conflicts:
#	packages/netlify-cms-widget-select/package.json
#	packages/netlify-cms/src/media-libraries.js
entry: './index.js',
mode: isProduction ? 'production' : 'development',
context: path.join(__dirname, 'dist'),
entry: './netlify-cms.esm.js',
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this really correct? I think webpack needs the raw source file. This could explain the large UMD bundle as well

@erquhart
Copy link
Contributor

erquhart commented Feb 2, 2019

Closing this as abandoned, but please reopen if you'd like to move this forward.

@erquhart
Copy link
Contributor

erquhart commented Apr 2, 2019

Update: this was addressed by @talves in #2214, #2141, and #2215.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants