Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

inline-resource-plugin

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

inline-resource-plugin

A webpack plugin to embed css/js resource in the html with inline-source module.

  • 0.6.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source
NPM version

inline-resource-plugin

A webpack plugin to embed css/js resource in the html with inline-source module.

Install

$ npm install inline-resource-plugin --save-dev

example

<!-- ./build/hello.html -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>test</title>
    <link href="inline.css" inline>
    <script src="inline.js" inline></script>
</head>
<body>
<div class="container">
    <h1>hello world!</h1>
</div>
</body>
</html>
/* ./src/inline.js */
function Person() {
}

Person.prototype.sayHello = function () {
    var word = 'hello';
    console.log(word);
};
/* ./src/inline.css */
.container {
    border: 1px solid #000000;
}

Output:

<!-- ./build/hello.html -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>test</title>
    <style>.container{border:1px solid #000}</style>
    <script>function Person(){}Person.prototype.sayHello=function(){var o="hello";console.log(o)};</script>
</head>
<body>
<div class="container">
    <h1>hello world!</h1>
</div>
</body>
</html>

Usage

Available options include:

  • compile: If the file that you want to embed need to be compiled(such as ES6 or require), you can pass 'true'.(default false)
  • compress: enable/disable compression.(default true)
  • rootpath: path used for resolving inlineable paths.
  • template: the path of your template file.This option is used for finding out the files which need to embed into the template.(required)
  • test: the file which you want to execute embed task.If you have multiple templates,you'd better use regx to specify the template that you want to execute inline task.
  • filename: If you decide to use the other plugins such as HtmlWebpackPlugin to generate template file,you can ignore this option.Or you can pass the path and we will generate template file by ourselves.

note: test and filename option at least one is needed(Refer to the example below).

// webpack.config.js example
const HtmlWebpackPlugin = require('html-webpack-plugin');
const InlineResourcePlugin = require('inline-resource-plugin');

module.exports = {
    entry: {
        hello: './src/hello'
    },
    output: {
        path: './build',
        publicPath: '/inline-resource-plugin/example/build/',
        filename: '[name].js'
    },
    plugins: [
        new HtmlWebpackPlugin({
            filename: 'hello_result.html',
            template: './src/hello.html',
            inject: 'body'
        }),
        new InlineResourcePlugin({ // this InlineResourcePlugin is work with HtmlWebpackPlugin(As it has supplied 'test' option)
            compile: true,
            compress: true,
            rootpath: './src',
            template: './src/hello.html', // Just keep the same with the 'template' option of HtmlWebpackPlugin
            test: /^hello_result\.html$/ // A regular expression that match the 'filename' option of HtmlWebpackPlugin
        }),
        new InlineResourcePlugin({ // this InlineResourcePlugin is work alone(As it has supplied 'filename' option)
            compile: false,
            compress: true,
            rootpath: './src',
            template: './src/world.html',
            filename: 'world_result.html' // If you use 'filename' option, you don't need to supply 'test' option
        })
    ]
};

note: You can find this demo in the example directory.

Events

Available event include:

  • inline-resource-plugin-html-after-emit: This event represent that the compile and embed task has been completed.You may need it when you use this plugin with hot module replacement feature.

example:

compiler.plugin('inline-resource-plugin-html-after-emit', function (data, callback) {
  hotMiddleware.publish({action: 'reload'});
  callback();
});

License

MIT License

Keywords

FAQs

Package last updated on 08 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc