Skip to content

Instantly share code, notes, and snippets.

@anandology
Created May 20, 2021 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anandology/3c63fe76273f9ba9806b0aeec180b948 to your computer and use it in GitHub Desktop.
Save anandology/3c63fe76273f9ba9806b0aeec180b948 to your computer and use it in GitHub Desktop.
Minimal test to reproduce issue with new frappe build system

This gist demonstrates one of the issues with the new build system of Frappe.

How to reproduce

Step 1

Add the sq.js and square.bundle.js from gist to apps/frappe/frappe/public/js in your bench.

Step 2

Run build.

$ bench build --app=frappe

Step 3

Look at the contents of dist/js/square.bundle.*.js.

$ cat apps/frappe/frappe/public/dist/js/square.bundle.*.js
(() => {
})();
//# sourceMappingURL=square.bundle.BGCA7SNG.js.map
function square(x) {
return x*x;
}
@netchampfaris
Copy link

netchampfaris commented May 20, 2021

This is tree shaking in action. You are not exporting the function nor you are assigning it some global variable, so it wont be available in the final bundle.

Try these changes:

// sq.js
export function square(x) {
	return x*x;
}

// square.bundle.js
import { square } from './sq';

console.log(square(2));

As far as I remember, you would get the same behaviour with the previous rollup based build.

@anandology
Copy link
Author

Thanks for the clarification.

I saw frappe/utils/datetime.js and that didn't had any exports. I thought it won't be need here as well.

I understand that now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment