Skip to content

Commit 979d3c8

Browse files
committed
feat: html inline script webpack plugin
0 parents  commit 979d3c8

17 files changed

+3673
-0
lines changed

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
max_line_length = 0
13+
indent_size = 4
14+
trim_trailing_whitespace = false

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
README.md

.eslintrc

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
"plugins": [
4+
"@typescript-eslint"
5+
],
6+
"extends": [
7+
"eslint:recommended",
8+
"plugin:@typescript-eslint/eslint-recommended",
9+
"plugin:@typescript-eslint/recommended",
10+
"airbnb-base"
11+
],
12+
"settings": {
13+
"import/resolver": {
14+
"node": {
15+
"extensions": [
16+
".js",
17+
".ts",
18+
".d.ts"
19+
]
20+
}
21+
}
22+
},
23+
"rules": {
24+
"no-param-reassign": "off",
25+
"comma-dangle": ["error", "never"],
26+
"import/no-extraneous-dependencies": [
27+
"error",
28+
{
29+
"optionalDependencies": false
30+
}
31+
],
32+
"import/extensions": [
33+
"error",
34+
{
35+
"js": "never",
36+
"ts": "never",
37+
}
38+
]
39+
}
40+
}

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.DS_Store
2+
node_modules
3+
4+
yarn-debug.log*
5+
yarn-error.log*
6+
7+
/dist

.huskyrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"hooks": {
3+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
4+
"pre-commit": "lint-staged"
5+
}
6+
}

.lintstagedrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"src/**/*.{json,md}": [
3+
"prettier --single-quote --write"
4+
],
5+
"src/**/*.{js,ts}": [
6+
"eslint --report-unused-disable-directives --fix --quiet"
7+
]
8+
}

.npmignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/src
2+
tsconfig.json
3+
.editorconfig
4+
.eslintrc
5+
.huskyrc
6+
.lintstagedrc
7+
.nvmrc
8+
.versionrc
9+
commitlint.config.js
10+
yarn-error.log
11+
yarn.lock

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
12.16.1

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Ice Lam
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# HTML Inline Script Webpack Plugin (html-inline-script-webpack-plugin)
2+
A webpack plugin for converting external script files `<script src="app.js"></script>` to inline script block `<script>...</script>`. Requires [html-webpack-plugin](https://github.com/jantimon/html-webpack-plugin) to work.
3+
4+
Inspired by [react-dev-utils](https://github.com/facebook/create-react-app/blob/master/packages/react-dev-utils/InlineChunkHtmlPlugin.js) created by [Facebook](https://github.com/facebook/).
5+
6+
## Install
7+
### NPM
8+
```bash
9+
npm i html-inline-script-webpack-plugin -D
10+
```
11+
### Yarn
12+
```bash
13+
yarn add html-inline-script-webpack-plugin -D
14+
```
15+
16+
## Usage
17+
By default, the plugin will convert all the external script files to inline script block.
18+
```js
19+
const HtmlWebpackPlugin = require('html-webpack-plugin');
20+
const HtmlInlineScriptPlugin = require('html-inline-script-webpack-plugin');
21+
22+
module.exports = {
23+
plugins: [
24+
new HtmlWebpackPlugin(),
25+
new HtmlInlineScriptPlugin(),
26+
]
27+
}
28+
```
29+
30+
To limit the scope of the plugin, specify lists of files you wish to convert in regular expressions:
31+
```js
32+
const HtmlWebpackPlugin = require('html-webpack-plugin');
33+
const HtmlInlineScriptPlugin = require('html-inline-script-webpack-plugin');
34+
35+
module.exports = {
36+
plugins: [
37+
new HtmlWebpackPlugin(),
38+
new HtmlInlineScriptPlugin([
39+
/runtime~.+[.]js/,
40+
/app~.+[.]js/
41+
]),
42+
]
43+
}
44+
```

0 commit comments

Comments
 (0)