Skip to content

Commit 7aff2e7

Browse files
committed
Merge branch 'develop'
2 parents 3060595 + 7c38441 commit 7aff2e7

File tree

16 files changed

+802
-349
lines changed

16 files changed

+802
-349
lines changed

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,13 @@ updates:
1818
reviewers:
1919
- "icelam"
2020
open-pull-requests-limit: 10
21+
- package-ecosystem: "github-actions"
22+
directory: "/"
23+
target-branch: "develop"
24+
schedule:
25+
interval: "monthly"
26+
commit-message:
27+
prefix: "ci"
28+
rebase-strategy: "auto"
29+
reviewers:
30+
- "icelam"

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ jobs:
2121
HUSKY: 0
2222
steps:
2323
- name: Checkout repo
24-
uses: actions/checkout@main
24+
uses: actions/checkout@v3
2525
- name: Setup Node.js version ${{ matrix.node-version }}
26-
uses: actions/setup-node@main
26+
uses: actions/setup-node@v3
2727
with:
2828
node-version: ${{ matrix.node-version }}
2929
- name: Get yarn cache directory path
3030
id: yarn-cache-dir-path
31-
run: echo "::set-output name=dir::$(yarn cache dir)"
31+
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
3232
- name: Restore yarn cache
33-
uses: actions/cache@v1
33+
uses: actions/cache@v3
3434
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
3535
with:
3636
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}

.github/workflows/codeql.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- develop
8+
tags-ignore:
9+
- '**' #prevent double build on release tag
10+
pull_request:
11+
branches:
12+
- '**'
13+
schedule:
14+
- cron: "14 14 * * 0"
15+
16+
jobs:
17+
analyze:
18+
name: Analyze
19+
runs-on: ubuntu-latest
20+
permissions:
21+
actions: read
22+
contents: read
23+
security-events: write
24+
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
language: [javascript]
29+
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v3
33+
34+
- name: Initialize CodeQL
35+
uses: github/codeql-action/init@v2
36+
with:
37+
languages: ${{ matrix.language }}
38+
queries: +security-and-quality
39+
40+
- name: Autobuild
41+
uses: github/codeql-action/autobuild@v2
42+
43+
- name: Perform CodeQL Analysis
44+
uses: github/codeql-action/analyze@v2
45+
with:
46+
category: "/language:${{ matrix.language }}"

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ jobs:
1111

1212
steps:
1313
- name: Checkout repo
14-
uses: actions/checkout@main
14+
uses: actions/checkout@v3
1515
- name: Setup Node.js version
16-
uses: actions/setup-node@main
16+
uses: actions/setup-node@v3
1717
with:
1818
node-version-file: '.nvmrc'
1919

.npmignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ commitlint.config.js
1111
yarn-error.log
1212
yarn.lock
1313
.github
14-
lgtm.yml
1514
/__tests__
1615
.husky
1716
/scripts

README.md

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
[![Install size](https://packagephobia.com/badge?p=html-inline-script-webpack-plugin)](https://packagephobia.com/result?p=html-inline-script-webpack-plugin)
66
![ci](https://github.com/icelam/html-inline-script-webpack-plugin/workflows/ci/badge.svg)
77
[![Package quality](https://npm.packagequality.com/shield/html-inline-script-webpack-plugin.svg)](https://packagequality.com/#?package=html-inline-script-webpack-plugin)
8-
[![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/icelam/html-inline-script-webpack-plugin.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/icelam/html-inline-script-webpack-plugin/context:javascript)
98

109
[![NPM](https://nodei.co/npm/html-inline-script-webpack-plugin.png?compact=true)](https://npmjs.org/package/html-inline-script-webpack-plugin)
1110

@@ -17,35 +16,19 @@ Inspired by [react-dev-utils](https://github.com/facebook/create-react-app/blob/
1716

1817
### Webpack5
1918

20-
#### NPM
21-
2219
```bash
2320
npm i html-inline-script-webpack-plugin -D
2421
```
2522

26-
#### Yarn
27-
28-
```bash
29-
yarn add html-inline-script-webpack-plugin -D
30-
```
31-
3223
### Webpack4
3324

34-
#### NPM
35-
3625
```bash
3726
npm i html-inline-script-webpack-plugin@^1 -D
3827
```
3928

40-
#### Yarn
41-
42-
```bash
43-
yarn add html-inline-script-webpack-plugin@^1 -D
44-
```
45-
4629
## Usage
4730

48-
By default, the plugin will convert all the external script files to inline script block.
31+
By default, the plugin will convert all the external script files to inline script block, and remove the original script file from build assets.
4932

5033
```js
5134
const HtmlWebpackPlugin = require('html-webpack-plugin');
@@ -64,6 +47,7 @@ Below are lists of options supported by this plugin:
6447
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
6548
| scriptMatchPattern | List of script files that should be processed and inject as inline script. This will be filtered using the output file name. | RegExp[] |
6649
| htmlMatchPattern | List of HTML template files that should be processed by this plugin. Useful when you have multiple `html-webpack-plugin` initialized. This will be filtered using the [`options?.filename`](https://github.com/jantimon/html-webpack-plugin#options) provided by `html-webpack-plugin`. | RegExp[] |
50+
| 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[] |
6751

6852
Here are some examples illustrating how to use these options:
6953

@@ -129,3 +113,43 @@ module.exports = {
129113
],
130114
};
131115
```
116+
##### Process any script files but preserve `main.js` from build assets
117+
118+
```js
119+
const HtmlWebpackPlugin = require('html-webpack-plugin');
120+
const HtmlInlineScriptPlugin = require('html-inline-script-webpack-plugin');
121+
122+
module.exports = {
123+
plugins: [
124+
new HtmlWebpackPlugin(),
125+
new HtmlInlineScriptPlugin({
126+
assetPreservePattern: [/main.js$/],
127+
}),
128+
],
129+
};
130+
```
131+
132+
## Contributors
133+
134+
Thanks goes to these wonderful people:
135+
136+
<table>
137+
<tbody>
138+
<tr>
139+
<td align="center" valign="top" width="20%">
140+
<a href="https://github.com/kmalakoff">
141+
<img src="https://avatars.githubusercontent.com/u/756520?s=120&v=4" width="60px;" alt="@kmalakoff"/>
142+
<br />
143+
<b>@kmalakoff</b>
144+
</a>
145+
</td>
146+
<td align="center" valign="top" width="20%">
147+
<a href="https://github.com/SorsOps">
148+
<img src="https://avatars.githubusercontent.com/u/80043879?s=120&v=4" width="60px;" alt="@kmalakoff"/>
149+
<br />
150+
<b>@SorsOps</b>
151+
</a>
152+
</td>
153+
</tr>
154+
</tbody>
155+
</table>

__tests__/HtmlInlineScriptPlugin.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import webpack from 'webpack';
55
import Self from '../dist';
66

77
import simpleConfig from './cases/simple/webpack.config';
8+
import preserveConfig from './cases/preserveAsset/webpack.config';
89
import multipleInstanceConfig from './cases/multiple-instance/webpack.config';
910
import jsWithImportConfig from './cases/js-with-import/webpack.config';
1011
import webWorkerConfig from './cases/web-worker/webpack.config';
@@ -48,6 +49,40 @@ describe('HtmlInlineScriptPlugin', () => {
4849
await webpackPromise;
4950
});
5051

52+
it('should preserve the output of an asset if requested', async () => {
53+
const webpackPromise = new Promise((resolve) => {
54+
const compiler = webpack(preserveConfig);
55+
console.log(preserveConfig)
56+
57+
compiler.run((error, stats) => {
58+
expect(error).toBeNull();
59+
60+
const statsErrors = stats?.compilation.errors;
61+
expect(statsErrors?.length).toBe(0);
62+
63+
const result = fs.readFileSync(
64+
path.join(__dirname, 'cases/preserveAsset/dist/index.html'),
65+
'utf8',
66+
);
67+
68+
const expected = fs.readFileSync(
69+
path.join(__dirname, 'cases/preserveAsset/expected/index.html'),
70+
'utf8',
71+
);
72+
expect(result).toBe(expected);
73+
74+
const expectedFileList = fs.readdirSync(path.join(__dirname, 'cases/preserveAsset/expected/'));
75+
const generatedFileList = fs.readdirSync(path.join(__dirname, 'cases/preserveAsset/dist/'));
76+
expect(expectedFileList.sort()).toEqual(generatedFileList.sort());
77+
78+
resolve(true);
79+
});
80+
});
81+
82+
await webpackPromise;
83+
});
84+
85+
5186
it('should build webpack config having multiple HTML webpack plugin instance without error', async () => {
5287
const webpackPromise = new Promise((resolve) => {
5388
const compiler = webpack(multipleInstanceConfig);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><meta name="language" content="English"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><meta name="viewport" content="minimum-scale=1,initial-scale=1,width=device-width,shrink-to-fit=no"/><title>webpack test</title><script defer="defer">console.log("Hello world");</script></head><body><p>This is minimal code to demonstrate webpack usage</p></body></html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("Hello world");
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6+
<meta name="language" content="English" />
7+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
8+
<meta name="viewport" content="minimum-scale=1, initial-scale=1, width=device-width, shrink-to-fit=no" />
9+
<title>webpack test</title>
10+
</head>
11+
<body>
12+
<p>This is minimal code to demonstrate webpack usage</p>
13+
</body>
14+
</html>

0 commit comments

Comments
 (0)