简体   繁体   中英

How to bundle html, js and css in one .js file?

I have simple app with index.html, style.css and app.js and i need to built a myBundle.js for easy implemantation in other site like:

<script type="text/javascript" src="myBundle.js"></script>

is that posible ?

You can bundle it all inside the HTML file if you'd like. That would be the easiest way to make it portable

So for example: yourfile.html

<html>
  <head>
  <style type="text/css">
  /* your CSS */
  </style>
  <script type="text/js">
  // your JS code
  </script>
  </head>
  <body></body>
 </html>

Then you can move the file anywhere and it will work independently.

As mentioned below this is not a clean way to code but it will work and is useful in some instances

这不是一个好主意,但也许您可以在 js 中创建元素,然后使用append()方法来放置您的 HTML / CSS

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM