All Projects → KyLeoHC → inline-source-webpack-plugin

KyLeoHC / inline-source-webpack-plugin

Licence: MIT license
A webpack plugin to embed css/js resource in the html.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to inline-source-webpack-plugin

InlineCssParser
A Visual Studio Extension that helps to extract inline styles into a seperate css file.
Stars: ✭ 23 (+27.78%)
Mutual labels:  inline-css, inline
Email Templates
📫 Create, preview, and send custom email templates for Node.js. Highly configurable and supports automatic inline CSS, stylesheets, embedded images and fonts, and much more!
Stars: ✭ 3,291 (+18183.33%)
Mutual labels:  inline-css, inline
image-sprite-webpack-plugin
A webpack plugin that generates spritesheets from your stylesheets.
Stars: ✭ 27 (+50%)
Mutual labels:  webpack-plugin
module-mapping-webpack-plugin
Webpack plugin for mapping modules onto different files
Stars: ✭ 25 (+38.89%)
Mutual labels:  webpack-plugin
flow-webpack-plugin
A webpack plugin allowing to call Flow type checker.
Stars: ✭ 36 (+100%)
Mutual labels:  webpack-plugin
webpack2-externals-plugin
Webpack 2+ fork of Webpack-Externals-Plugin
Stars: ✭ 14 (-22.22%)
Mutual labels:  webpack-plugin
compact str
A memory efficient string type that can store up to 24* bytes on the stack
Stars: ✭ 322 (+1688.89%)
Mutual labels:  inline
css-chunks-html-webpack-plugin
Injecting css chunks extracted using extract-css-chunks-webpack-plugin to HTML for html-webpack-plugin
Stars: ✭ 22 (+22.22%)
Mutual labels:  webpack-plugin
meteor-imports-webpack-plugin
Webpack plugin to import and use Meteor packages like if they were real NPM packages.
Stars: ✭ 25 (+38.89%)
Mutual labels:  webpack-plugin
generate-package-json-webpack-plugin
Generates a package.json file containing the external modules used by your webpack bundle
Stars: ✭ 59 (+227.78%)
Mutual labels:  webpack-plugin
mangle-css-class-webpack-plugin
Minifies and obfuscates the class names in your existing JavaScript, CSS, and HTML without any modern css modules.
Stars: ✭ 96 (+433.33%)
Mutual labels:  webpack-plugin
inline.js
Live CSS Helpers with Javascript
Stars: ✭ 36 (+100%)
Mutual labels:  inline-css
nova-inline-morph-to
A Laravel Nova field for displaying morphTo relationship inline.
Stars: ✭ 32 (+77.78%)
Mutual labels:  inline
amp-react-renderer-plugin
⚡Plugin makes it painless to create React component based AMP page⚡
Stars: ✭ 29 (+61.11%)
Mutual labels:  webpack-plugin
2018-package-three-webpack-plugin
[ARCHIVED] Webpack plugin to use Three.js "examples" classes
Stars: ✭ 45 (+150%)
Mutual labels:  webpack-plugin
tde-webpack-mjml-plugin
Webpack plugin for converting MJML files to HTML
Stars: ✭ 12 (-33.33%)
Mutual labels:  webpack-plugin
prettier-eslint-webpack-plugin
Webpack plugin for prettier-eslint which ESLint's settings is set to JavaScript Standard Style
Stars: ✭ 24 (+33.33%)
Mutual labels:  webpack-plugin
stylelint-bare-webpack-plugin
Stylelint plugin for webpack
Stars: ✭ 15 (-16.67%)
Mutual labels:  webpack-plugin
webpack-shower
🚿 Clean up, Arrange, Filter Webpack Stats
Stars: ✭ 12 (-33.33%)
Mutual labels:  webpack-plugin
editorjs-inline
Inline-Editor.js Tool for Editor.js
Stars: ✭ 23 (+27.78%)
Mutual labels:  inline

npm Version Build Status Codecov

inline-source-webpack-plugin

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

Install

$ npm i inline-source-webpack-plugin -D

example

<!-- ./demo/src/index.html -->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>test</title>
    <link href="inline.css" inline="true">
    <script src="inline.js" inline="true"></script>
  </head>
  <body>
    <div class="container">
      <h1>hello world!</h1>
    </div>
    <!-- 'inline-asset' attribute tell us to embed file that generated by webpack -->
    <script inline inline-asset="runtime\.\w+\.js$" inline-asset-delete></script>
    <script inline inline-asset="bundle\.\w+\.js$" inline-asset-delete></script>
  </body>
</html>

You can find this demo in the demo directory and view the output:

# install dependency
npm i

# build demo
npm run build:demo

Usage

Available options include(refer to this for more options):

  • compress: enable/disable compression.(default false)
  • rootpath: path used for resolving inlineable paths.
  • noAssetMatchReplace: work with noAssetMatch option.(default <!-- -->)
  • noAssetMatch: define the behaviour while no asset match the value of inline-asset attribute.(default none)
    • none: do nothing and the tag is still reserved in the html.
    • warn: throw warning tips and replace the tag with the content of noAssetMatchReplace option.
    • error: throw error tips and replace the tag with the content of noAssetMatchReplace option(This level will affect the compilation of webpack).
// webpack.config.js
const HtmlWebpackPlugin = require('html-webpack-plugin');
const InlineSourceWebpackPlugin = require('inline-source-webpack-plugin');

module.exports = {
  ...,
  plugins: [
    new HtmlWebpackPlugin({
      ...
    }),
    new InlineSourceWebpackPlugin({
      compress: true,
      rootpath: './src',
      noAssetMatch: 'warn'
    })
  ]
};

If you want to embed the files that generated by webpack or other plugin, you can use inline-asset attribute to filter the files(Please don't try to use src or href). Add inline-asset-delete attribute for deleting the asset after inline task.

<script inline inline-asset-delete inline-asset="Your asset path/Your asset name"></script>

The value of inline-asset attribute is a regular expression.

Note: For inline-asset feature, you may notice the 'no asset match' warning or error in developement mode as you write the regular expression for the production mode.Just ignore the 'no asset match' warning or error while in developement mode.Or you can provide noAssetMatch option for ignoring the warning or error;

License

MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].