Skip to content

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

License

Notifications You must be signed in to change notification settings

Linnanli/inline-script-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published