Skip to content

Commit

Permalink
Merge pull request #7 from Applelo/dev
Browse files Browse the repository at this point in the history
Version 2.0.0
  • Loading branch information
Applelo committed Nov 26, 2023
2 parents 54a9be4 + b2434ef commit 7e63e3f
Show file tree
Hide file tree
Showing 39 changed files with 4,740 additions and 956 deletions.
30 changes: 19 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,29 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x]
node_version: [14, 16, 18, 20]
os: [ubuntu-latest, windows-latest, macos-latest]
include:
# Active LTS + other OS
- os: macos-latest
node_version: 18
- os: windows-latest
node_version: 18
fail-fast: false

steps:
- uses: actions/checkout@v3

- uses: pnpm/action-setup@v2
- name: Install pnpm (node 14, pnpm 7)
if: matrix.node_version == 14
uses: pnpm/action-setup@v2.2.4
with:
version: 7

- name: Install pnpm
if: matrix.node_version != 14
uses: pnpm/action-setup@v2.2.4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
Expand All @@ -51,13 +63,11 @@ jobs:
fetch-depth: 0

- uses: pnpm/action-setup@v2
with:
version: 7

- name: Set node version to 16
- name: Set node version to 20
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 20
cache: pnpm

- name: Install
Expand All @@ -76,21 +86,19 @@ jobs:

lint:
runs-on: ubuntu-latest
name: 'Lint: node-16, ubuntu-latest'
name: 'Lint: node-20, ubuntu-latest'

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: pnpm/action-setup@v2
with:
version: 7

- name: Set node version to 16
- name: Set node version to 20
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 20
cache: pnpm

- name: Install
Expand Down
60 changes: 50 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
This plugin adds preload links by getting output assets from the build tools you are using.

Supporting:
- Vite 3 and 4 **(on build only)**
- Webpack 5 (with HTMLWebpackPlugin 5)
<!-- - Rspack -->
- Vite 4 and 5 **(on build only)**
- Webpack 5 (with [HtmlWebpackPlugin 5](https://github.com/jantimon/html-webpack-plugin))
- Rspack (with [HtmlWebpackPlugin 5](https://github.com/jantimon/html-webpack-plugin) or [HtmlRspackPlugin](https://www.rspack.dev/config/plugins.html#htmlrspackplugin))

> [!NOTE]
> This plugin combines [vite-plugin-inject-preload](https://github.com/Applelo/vite-plugin-inject-preload) and [html-webpack-inject-preload](https://github.com/principalstudio/html-webpack-inject-preload) into one package.
> [!NOTE]
>
> See the [migration guide](#migrate) for `vite-plugin-inject-preload` and `html-webpack-inject-preload` .
## Install
Expand Down Expand Up @@ -42,13 +41,12 @@ export default defineConfig({

Example: [`playground/vitejs`](./playground/vitejs)

> [!IMPORTANT]
> The Vite plugin [only works on build](https://github.com/Applelo/vite-plugin-inject-preload/issues/15) because of the way Vite behave.
<br></details>

<details>
<summary>Webpack (with HTMLWebpackPlugin)</summary><br>
<summary>Webpack (with HtmlWebpackPlugin)</summary><br>

```ts
// webpack.config.js
Expand All @@ -57,7 +55,7 @@ const UnpluginInjectPreload = require('unplugin-inject-preload/webpack')

module.exports = {
plugins: [
HtmlWebpackPlugin(),
HtmlWebpackPlugin({ /* HtmlWebpackPlugin options */ }),
UnpluginInjectPreload({ /* options */ }),
]
}
Expand All @@ -67,8 +65,50 @@ Example: [`playground/webpack`](./playground/webpack)

<br></details>

<details>
<summary>Rspack (with HtmlWebpackPlugin)</summary><br>

```ts
// rspack.config.js
const HtmlWebpackPlugin = require('html-webpack-plugin')
const UnpluginInjectPreload = require('unplugin-inject-preload/rspack')

module.exports = {
plugins: [
HtmlWebpackPlugin({ /* HtmlWebpackPlugin options */ }),
UnpluginInjectPreload({ /* options */ }),
]
}
```

Example: [`playground/rspack`](./playground/rspack)

<br></details>

<details>
<summary>Rspack (with HtmlRspackPlugin)</summary><br>

```ts
// rspack.config.js
const HtmlWebpackPlugin = require('html-webpack-plugin')
const UnpluginInjectPreload = require('unplugin-inject-preload/rspack')

module.exports = {
plugins: [
new rspack.HtmlRspackPlugin({ /* HtmlRspackPlugin options */ }),
UnpluginInjectPreload({ /* options */ }),
]
}
```

Example: [`playground/rspack`](./playground/rspack)

<br></details>

## 👨‍💻 Usage

> All example are presented for ViteJS but this is the same behavior for Webpack and RsPack
All the files needs to be process by the bundler to be find by the plugin. For example, if I load this CSS file :

```css
Expand Down Expand Up @@ -165,7 +205,7 @@ export default {
{
"devDependencies": {
- "vite-plugin-inject-preload": "*",
+ "unplugin-inject-preload": "^1.1.0",
+ "unplugin-inject-preload": "^2.0.0",
}
}
```
Expand Down Expand Up @@ -205,7 +245,7 @@ export default {
{
"devDependencies": {
- "@principalstudio/html-webpack-inject-preload": "*",
+ "unplugin-inject-preload": "^1.1.0",
+ "unplugin-inject-preload": "^2.0.0",
}
}
```
Expand Down
40 changes: 25 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "unplugin-inject-preload",
"type": "module",
"version": "1.1.1",
"packageManager": "pnpm@8.7.0",
"version": "2.0.0",
"packageManager": "pnpm@8.11.0",
"description": "Inject <link rel='preload'> for Webpack/ViteJS",
"license": "MIT",
"homepage": "https://github.com/applelo/unplugin-inject-preload#readme",
Expand All @@ -17,6 +17,7 @@
"unplugin",
"vite",
"webpack",
"rspack",
"html-webpack-plugin",
"html",
"link",
Expand All @@ -39,6 +40,11 @@
"import": "./dist/webpack.js",
"require": "./dist/webpack.cjs"
},
"./rspack": {
"types": "./dist/rspack.d.ts",
"import": "./dist/rspack.js",
"require": "./dist/rspack.cjs"
},
"./types": {
"types": "./dist/types.d.ts",
"import": "./dist/types.js",
Expand Down Expand Up @@ -69,7 +75,7 @@
"build:fix": "esno scripts/postbuild.ts",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"typecheck": "tsc --noEmit src/**/*.ts",
"typecheck": "tsc --noEmit --skipLibCheck",
"prepublishOnly": "pnpm build",
"test": "vitest",
"coverage": "vitest run --coverage"
Expand All @@ -84,24 +90,28 @@
},
"dependencies": {
"mime-types": "^2.1.35",
"unplugin": "^1.5.0"
"unplugin": "^1.5.1",
"webpack-sources": "^3.2.3"
},
"devDependencies": {
"@antfu/eslint-config": "1.0.0-beta.18",
"@types/mime-types": "^2.1.2",
"@types/node": "^20.8.0",
"@antfu/eslint-config": "2.1.0",
"@rspack/core": "^0.4.0",
"@types/mime-types": "^2.1.4",
"@types/node": "^20.10.0",
"@types/webpack-sources": "^3.2.3",
"@vitest/coverage-v8": "^0.34.6",
"css-loader": "^6.8.1",
"esno": "^0.17.0",
"fast-glob": "^3.3.1",
"esno": "^4.0.0",
"fast-glob": "^3.3.2",
"html-webpack-plugin": "^5.5.3",
"mini-css-extract-plugin": "^2.7.6",
"ts-loader": "^9.4.4",
"tsup": "^7.2.0",
"tsx": "^3.13.0",
"typescript": "^5.2.2",
"vite": "^4.4.9",
"prettier": "^3.1.0",
"ts-loader": "^9.5.1",
"tsup": "^8.0.1",
"tsx": "^4.5.0",
"typescript": "^5.3.2",
"vite": "^5.0.2",
"vitest": "^0.34.6",
"webpack": "^5.88.2"
"webpack": "^5.89.0"
}
}
8 changes: 8 additions & 0 deletions playground/rspack/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<!--__unplugin-inject-preload__-->
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
11 changes: 11 additions & 0 deletions playground/rspack/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"private": true,
"scripts": {
"dev": "rspack serve",
"build": "rspack build"
},
"devDependencies": {
"@rspack/cli": "0.4.0",
"unplugin-inject-preload": "workspace:*"
}
}
72 changes: 72 additions & 0 deletions playground/rspack/rspack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const rspack = require('@rspack/core')
const UnpluginInjectPreload = require('unplugin-inject-preload/rspack').default
// const HtmlWebpackPlugin = require('html-webpack-plugin')

/** @type {import('@rspack/cli').Configuration} */
const config = {
context: __dirname,
entry: './../src/main.ts',
output: {
publicPath: 'dist',
filename: 'main.js',
path: 'dist',
clean: true,
assetModuleFilename: '[name].[hash][ext][query]',
},
module: {
rules: [
{
test: /\.css$/i,
type: 'css',
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/resource',
},
],
},
plugins: [
new rspack.HtmlRspackPlugin({
minify: false,
templateContent: `
<!DOCTYPE html>
<html>
<head>
<!--__unplugin-inject-preload__-->
</head>
<body>
<h1>Hello World</h1>
</body>
</html>`,
}),
// new HtmlWebpackPlugin({
// inject: false,
// minify: false,
// templateContent: ({ htmlWebpackPlugin }) => `
// <!DOCTYPE html>
// <html>
// <head>
// <!--__unplugin-inject-preload__-->
// ${htmlWebpackPlugin.tags.headTags}
// </head>
// <body>
// <h1>Hello World</h1>
// ${htmlWebpackPlugin.tags.bodyTags}
// </body>
// </html>
// `,
// }),
UnpluginInjectPreload({
injectTo: 'custom',
files: [
{
outputMatch: /Roboto-[a-zA-Z]*.[a-z-0-9]*\.woff2$/,
},
{
outputMatch: /^(?!main).*\.(css|js)$/,
},
],
}),
],
}
module.exports = config
7 changes: 4 additions & 3 deletions playground/vitejs/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"type": "module",
"private": true,
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
},
"devDependencies": {
"typescript": "^5.2.2",
"typescript": "^5.3.2",
"unplugin-inject-preload": "workspace:*",
"vite": "^4.4.9",
"vite-plugin-inspect": "^0.7.38"
"vite": "^5.0.2",
"vite-plugin-inspect": "^0.7.42"
}
}
8 changes: 4 additions & 4 deletions playground/vitejs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"sourceMap": true,
"noEmit": true,
"isolatedModules": true,
"esModuleInterop": true,
"strict": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noEmit": true,
"sourceMap": true,
"esModuleInterop": true,
"isolatedModules": true,
"skipLibCheck": true
},
"include": ["./../src", "main.ts"]
Expand Down
Loading

0 comments on commit 7e63e3f

Please sign in to comment.