简体   繁体   English

如何将 html、js 和 css 捆绑在一个 .js 文件中?

[英]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:我有一个带有 index.html、style.css 和 app.js 的简单应用程序,我需要构建一个 myBundle.js 以便在其他站点中轻松实现,例如:

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

is that posible ?那可能吗?

You can bundle it all inside the HTML file if you'd like.如果您愿意,您可以将其全部捆绑在 HTML 文件中。 That would be the easiest way to make it portable这将是使其便携的最简单方法

So for example: yourfile.html例如: 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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