Skip to content

Commit

Permalink
PKG -- [fcl] Minify UMD build (#1359)
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink authored Aug 22, 2022
1 parent ec6f6a6 commit 9ea9885
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 115 deletions.
5 changes: 5 additions & 0 deletions .changeset/clean-years-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@onflow/fcl": patch
---

Minify UMD build
5 changes: 5 additions & 0 deletions .changeset/swift-chairs-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@onflow/fcl-bundle": minor
---

Automatically compress bundle if entry file ends in .min.js
113 changes: 83 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/fcl-bundle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ All of the configuration for FCL-Bundle currently takes place within the `packag
| `module` | No | string | Specify esm bundle output path if not manually specified by [Output Configuration](#output-configuration) (as well as esm entry point if not overriden by `package.exports`) |
| `unpkg` | No | string | Specify umd bundle output path if not manually specified by [Output Configuration](#output-configuration) (as well as umd entry point if not overriden by `package.exports`) |

> **Note:** If output paths end in ".min.js", the resulting bundle will be minified

### Output Configuration

Expand All @@ -35,6 +37,8 @@ An empty Output Configuration will fallback to the [default outputs](#default-ou

In practice, these Output Configuration objects will be consumed as shown in the [Source Configuration](#source-configuration) below.

> **Note:** If output paths end in ".min.js", the resulting bundle will be minified
### Source Configuration

A source configuration can be provided in one of three ways:
Expand Down
3 changes: 2 additions & 1 deletion packages/fcl-bundle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"commander": "^9.3.0",
"lodash": "^4.17.21",
"rollup": "^2.75.5",
"rollup-plugin-sourcemaps": "^0.6.3"
"rollup-plugin-sourcemaps": "^0.6.3",
"rollup-plugin-terser": "^7.0.2"
},
"bin": {
"fcl-bundle": "src/cli.js"
Expand Down
29 changes: 9 additions & 20 deletions packages/fcl-bundle/src/build/build-watch.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const WatcherFactory = require("./watcher-factory")
const WatcherPool = require("./watcher-pool")
const {watch} = require("rollup")

const getInputOptions = require("./get-input-options")
const getOutputOptions = require("./get-output-options")

module.exports = async function buildModulesWatch(builds, package) {
const watcherFactory = new WatcherFactory(builds.length)
watcherFactory.eventEmitter.on("event", handleWatcherEvent)

await Promise.all(
builds.map(build => buildModuleWatch(build, package, watcherFactory))
const watcherOptionsList = builds.map(build =>
getWatcherOptions(build, package)
)
const watcherPool = new WatcherPool(watcherOptionsList)
watcherPool.on("event", handleWatcherEvent)

function handleWatcherEvent(event) {
switch (event.code) {
Expand All @@ -27,24 +27,13 @@ module.exports = async function buildModulesWatch(builds, package) {
}
}

async function buildModuleWatch(build, package, watcherFactory) {
function getWatcherOptions(build, package) {
const inputOptions = getInputOptions(package, build)
const outputOptions = getOutputOptions(package, build)
const watchOptions = {
const watcherOptions = {
...inputOptions,
output: [outputOptions],
}

let watcher, buildError
try {
watcher = watcherFactory.makeWatcher(watchOptions)
} catch (error) {
buildError = error
}

if (watcher) watcher.close()

if (buildError) {
throw new Error(buildError)
}
return watcherOptions
}
Loading

0 comments on commit 9ea9885

Please sign in to comment.