Skip to content

Instantly share code, notes, and snippets.

@Braunson
Created March 2, 2018 22:24
Show Gist options
  • Save Braunson/cde3b6a6bae03f81daeda7f590ad8af2 to your computer and use it in GitHub Desktop.
Save Braunson/cde3b6a6bae03f81daeda7f590ad8af2 to your computer and use it in GitHub Desktop.
Laravel Mix - Making functions and variables accessible in the global scope/object

To explain why to use the window. notation a little more (because I was confused at some point with it too) Webpack wraps your code in functions to create scope, so that each file can act as an independent module. This keeps your various modules from polluting the global scope or each other and also means test is not available to the browser console. If you just want to call your test function from the browser console try assigning test to the window object.

There's a great answer at SO on options with several approaches for globals here https://stackoverflow.com/a/40416826/610880

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