Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork10
A webpack plugin for converting external script files to inline script block. Requires 'html-webpack-plugin' to work.
License
icelam/html-inline-script-webpack-plugin
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A webpack plugin for converting external script files<script src="app.js"></script>
to inline script block<script>...</script>
. Requireshtml-webpack-plugin to work.
Inspired byreact-dev-utils created byFacebook.
npm i html-inline-script-webpack-plugin -D
npm i html-inline-script-webpack-plugin@^1 -D
By default, the plugin will convert all the external script files to inline script block, and remove the original script file from build assets.
constHtmlWebpackPlugin=require('html-webpack-plugin');constHtmlInlineScriptPlugin=require('html-inline-script-webpack-plugin');module.exports={plugins:[newHtmlWebpackPlugin(),newHtmlInlineScriptPlugin()],};
Below are lists of options supported by this plugin:
Name | Description | Type |
---|---|---|
scriptMatchPattern | List of script files that should be processed and inject as inline script. This will be filtered using the output file name. | RegExp[] |
htmlMatchPattern | List of HTML template files that should be processed by this plugin. Useful when you have multiplehtml-webpack-plugin initialized. This will be filtered using theoptions?.filename provided byhtml-webpack-plugin . | RegExp[] |
assetPreservePattern | List of script files that should be preserved by this plugin after inserting them inline. This will be filtered using the output file name. | RegExp[] |
Here are some examples illustrating how to use these options:
constHtmlWebpackPlugin=require('html-webpack-plugin');constHtmlInlineScriptPlugin=require('html-inline-script-webpack-plugin');module.exports={plugins:[newHtmlWebpackPlugin(),newHtmlInlineScriptPlugin({scriptMatchPattern:[/runtime~.+[.]js$/,/app~.+[.]js$/],}),],};
constHtmlWebpackPlugin=require('html-webpack-plugin');constHtmlInlineScriptPlugin=require('html-inline-script-webpack-plugin');module.exports={plugins:[newHtmlWebpackPlugin({filename:'index.html',template:'static/index.webos.html',}),newHtmlWebpackPlugin({filename:'page2.html',template:'page2.html',}),newHtmlInlineScriptPlugin({htmlMatchPattern:[/index.html$/],}),],};
constHtmlWebpackPlugin=require('html-webpack-plugin');constHtmlInlineScriptPlugin=require('html-inline-script-webpack-plugin');module.exports={plugins:[newHtmlWebpackPlugin({filename:'index.html',template:'static/index.webos.html',}),newHtmlWebpackPlugin({filename:'page2.html',template:'page2.html',}),newHtmlInlineScriptPlugin({scriptMatchPattern:[/runtime~.+[.]js$/,/app~.+[.]js$/],htmlMatchPattern:[/index.html$/],}),],};
constHtmlWebpackPlugin=require('html-webpack-plugin');constHtmlInlineScriptPlugin=require('html-inline-script-webpack-plugin');module.exports={plugins:[newHtmlWebpackPlugin(),newHtmlInlineScriptPlugin({assetPreservePattern:[/main.js$/],}),],};
- This plugin does not transform Web Worker syntax like `new Worker(new URL('./worker.js', import.meta.url));``. It simply embeds the source code processed by webpack into HTML files, and emits any JavaScript files that is not processed by the plugin.
- This plugin is designed to embed script content into HTML files for deployment to environments where only a single file can be uploaded, or where the script file itself is small enough that it doesn't warrant an additional HTTP request. It is not intended for use in development, and may fail if HMR is enabled.
- This plugin does not support inlining scripts that are dynamically imported (the
import()
syntax). The reason is explained inthis issue.
Thanks goes to these wonderful people:
@kmalakoff | @SorsOps |
About
A webpack plugin for converting external script files to inline script block. Requires 'html-webpack-plugin' to work.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors4
Uh oh!
There was an error while loading.Please reload this page.