Skip to content

Commit

Permalink
Use iife when bundling browser apps (#880)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigma-andex authored May 2, 2022
1 parent 744bdbb commit 9a6a628
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 22 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

Other improvements:
- Use `iife` format when bundling browser apps (#880)

## [0.20.8] - 2022-04-27

Features:
Expand Down
5 changes: 4 additions & 1 deletion src/Spago/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,10 @@ bundleWithEsbuild withMain srcMap (ModuleName moduleName) (TargetPath targetPath
srcMapOpt = case srcMap of
WithSrcMap -> ["--sourcemap"]
WithoutSrcMap -> []
esbuildBase = platformOpt <> minifyOpt <> srcMapOpt <> ["--format=esm", "--bundle", "--outfile=" <> targetPath]
formatOpt = case (platform, withMain) of
(Browser, WithMain) -> ["--format=iife"]
(_,_) -> ["--format=esm"]
esbuildBase = platformOpt <> minifyOpt <> srcMapOpt <> formatOpt <> ["--bundle", "--outfile=" <> targetPath]
(input, cmd) = case withMain of
WithMain -> do
let
Expand Down
20 changes: 11 additions & 9 deletions test/fixtures/bundle-app-esm.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// output/Effect.Console/foreign.js
var log = function(s) {
return function() {
console.log(s);
(() => {
// output/Effect.Console/foreign.js
var log = function(s) {
return function() {
console.log(s);
};
};
};

// output/Main/index.js
var main = /* @__PURE__ */ log("\u{1F35D}");
// output/Main/index.js
var main = /* @__PURE__ */ log("\u{1F35D}");

// <stdin>
main();
// <stdin>
main();
})();
20 changes: 11 additions & 9 deletions test/fixtures/bundle-app-src-map-esm.js

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

5 changes: 2 additions & 3 deletions test/fixtures/packages-prepare-0-15.dhall
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
let upstream =
https://github.com/JordanMartinez/package-sets/releases/download/psc-0.15.0-20220329/packages.dhall

in upstream
https://github.com/purescript/package-sets/releases/download/psc-0.15.0-20220429/packages.dhall
in upstream

0 comments on commit 9a6a628

Please sign in to comment.