Skip to content

Latest commit

 

History

History
164 lines (121 loc) · 2.29 KB

README.md

File metadata and controls

164 lines (121 loc) · 2.29 KB

inline-script-loader

This is a webpack loader that can embed javascript in html.

📘 中文文档

Installation

npm

$ npm install inline-script-loader --save-dev

yarn

$ yarn add inline-script-loader -D

Usage

Create a javascript file: common/lib/global.js

var global = {
    name:'inline-script-loader'
};

And introduced in the src/index.html template file

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Document</title>
    <%= require('inline-script-loader!common/lib/global.js') %>
</head>
<body>
</body>
</html>

Finally webpack output dist/index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Document</title>
    <script type="text/javascript">
        var global = {
            name:'inline-script-loader'
        };
    </script>
</head>
<body>
</body>
</html>

Options

id

Define the id of the inline script <script> tag

  • example
require('inline-script-loader?id=inline-script!common/lib/global.js')
  • output
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Document</title>
    <script type="text/javascript" id="inline-script">
        var global = {
            name:'inline-script-loader'
        };
    </script>
</head>
<body>
</body>
</html>

type

Define the type attribute of the inline script <script> tag

  • example
require('inline-script-loader?type=text/ecmascript!common/lib/global.js')
  • output
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Document</title>
    <script type="text/ecmascript">
        var global = {
            name:'inline-script-loader'
        };
    </script>
</head>
<body>
</body>
</html>

isUglify

Whether to compress the script

  • example
require('inline-script-loader?isUglify=true!common/lib/global.js')
  • output
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Document</title>
    <script type="text/ecmascript">
        var global={name:'inline-script-loader'};
    </script>
</head>
<body>
</body>
</html>

License