npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

inline-resource-plugin

v0.6.3

Published

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

Downloads

27

Readme

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