Skip to content

Instantly share code, notes, and snippets.

@dfparker2002
Forked from mgol/jquery-es6-example.md
Created November 20, 2019 10:00
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 dfparker2002/f0aaa55c4ac29437de4a4d00bad0a9cf to your computer and use it in GitHub Desktop.
Save dfparker2002/f0aaa55c4ac29437de4a4d00bad0a9cf to your computer and use it in GitHub Desktop.
jQuery ES6 modules example usage

jQuery source is now authored using ES6 modules. It's possible to use them directly in the browser without any build process.

To test it locally, first clone the jQuery repository:

git clone git@github.com:jquery/jquery.git

Then, write the following index.html file:

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>jQuery ES6 modules test page</title>
</head>
<body>
  <div id="message"></div>
  <script type="module">
	  import $ from "./jquery/src/jquery.js";
	  $('#message').text('Hi from jQuery!');
  </script>
</body>
</html>

Afterwards, run a local HTTP server in the current directory:

npx http-server -p 3000

Then open http://localhost:3000 in your web browser and see jQuery did its work.

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