-
Notifications
You must be signed in to change notification settings - Fork 88
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
📦 Chore(build): migrate to esbuild and change export assignment to esm export #102
Conversation
It's a breaking change since the developer should change the usage of picgo. We should export commonJS & ESM both |
the node developer will use |
@Molunerfinn Since we have changed the export method of PicGo, now user has to use this import method: // CJS
const { PicGo } = require('picgo') // or const PicGo = require('picgo').PicGo
// ESM
import { PicGo } from 'picgo' There are a lot of libraries are using this export method, such as liquidjs:
Ok, I found a way to hack and support both method. I will give a repo in several minutes. |
@Molunerfinn I have done some test that there is a way to support both style import/require, you can see my demo here: https://github.com/upupming/ts-export-test. What do you think, if you agree the method linked in the repo, I will implement it in picgo-core~ |
rollup+umd would be better |
@Molunerfinn Do you mean support browser environment in the future? ESBuild can supports UMD, too, but we have to use custom I think the switch to esbuild or Rollup is quite easy and will not affect any user. We can build UMD bundle once we don't relay on Node.js environment anymore (such as dynamic |
the big problem is that esbuild just supports to es6 |
@Molunerfinn Yes, but I think we can simply assume that all user has a Node.js environment that supports ES6 at the present. Anyway, If you prefer rollup, I will change to rollup, the major benefits of esbuild is faster. What do you think? |
|
@Molunerfinn Ok, I know it, and I will change the esbuild to rollup and solve the version problem. |
@Molunerfinn I have changed the build tool from esbuild to rollup, here are the build results: |
Nice. Have you tested the clipboard image uploading process in mac or win? This PR will be merged If I have time to test. And It will be a breaking change since we change the export way. It will be released in |
@Molunerfinn I have test CLI & vs-picgo integration & PicGo-Electron integration on mac. And also I tested the CLI on Windows, below is the generated ps1 file at the runtime: The clipboard feature works like a charm! |
Fixes #101, #42
In this PR, I use esbuild to build both cjs and esm bundle for picgo-core. All dependencies are externalized, so the bundle is minimized to only ~280KB:
❯ ls -lh dist/*.js -rw-r--r-- 1 upupming staff 278K Oct 4 23:11 dist/index.cjs.js -rw-r--r-- 1 upupming staff 273K Oct 4 23:11 dist/index.esm.js
I have also tried to use rollup, but I found it is too slow to build, and have to use
tsc
to generate .d.ts files too, because this usage will cause rollup typescript plugin trying to generatedist/src/index.d.ts
instead ofdist/index.d.ts
(see ezolenko/rollup-plugin-typescript2#275 (comment)):So finally I write a custom esbuild script for this task.