Importing an ES6 module for use with single html page without local node server, angular or react

I'm currently doing a small from which only contains a html5 pages .. index.html.

Currently I am adding the javascript code to the actual page between script tags.

What I want to do is to create an ES6 module and import it to to this index.html page.

But I want to do this without having to use node, angular or react in a project.

What is the easiest ay to do this with my layout?
LVL 1
error2013Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
You could use Babel to transpile your ES6 code to ES5 - that is the standard way of doing it
0
error2013Author Commented:
I'm reading that I can use babel on my index.html as a standalone via cdn?

If so how would I use it?
0
Julian HansenCommented:
You can but why would you want to do that? It is just adding an overhead to your page repeating the same transpile against a static source.

Why not use webpack or similar to build your site - do the transpile of your module and produce an optimised output.
0
error2013Author Commented:
Because this is just for a quick thing I'm doing for testing some stuff
0
Julian HansenCommented:
Then just add the babel plugin and declare your scripts in a babel script block
<script type="text/babel">
...
</script>

Open in new window

Example
<!doctype html>
<html>
<head>
<title>Test Bable</title>
</head>
<body>
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
<script type="text/babel">
var x = ['apple','dog','cat','monkey','car'];

var p = x.filter(aa => {
  return aa.indexOf('c') > -1;
});
console.log(p);
</script>
</body>

Open in new window

More information here https://babeljs.io/docs/setup/#installation
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Node.js

From novice to tech pro — start learning today.