Skip to content

Commit

Permalink
feat: add dll & dll-reference plugin examples (#169)
Browse files Browse the repository at this point in the history
Co-authored-by: 谢奇璇 <[email protected]>
  • Loading branch information
GiveMe-A-Name and 谢奇璇 authored Nov 15, 2024
1 parent bfae810 commit 36a148d
Show file tree
Hide file tree
Showing 11 changed files with 342 additions and 43 deletions.
281 changes: 238 additions & 43 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions rspack/dll-reference/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import a from '../dll/a';
import alpha from '../dll/alpha';
import beta from 'beta/beta'
import b from 'beta/b'
import c from 'beta/c'
import _ from 'lodash';


console.log(a)
console.log(alpha)
console.log(beta)
console.log(b)
console.log(c)
console.log(_.sum([1, 2]))
14 changes: 14 additions & 0 deletions rspack/dll-reference/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "example-dll-reference-plugin",
"private": true,
"scripts": {
"dev": "rspack serve",
"build": "rspack build || echo 'make-ci-happy'"
},
"devDependencies": {
"@rspack/cli": "1.1.1",
"@rspack/core": "1.1.1",
"typescript": "^5.3.3",
"lodash": "4.17.21"
}
}
28 changes: 28 additions & 0 deletions rspack/dll-reference/rspack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

const rspack = require('@rspack/core')
const path = require('node:path');

/** @type {import('@rspack/cli').Configuration} */
const config = {
entry: './index',
output: {
path: path.resolve(__dirname, 'dist'),
},
resolve: {
extensions: ['...', '.ts', '.tsx', '.js', '.jsx']
},
plugins: [
new rspack.DllReferencePlugin({
manifest: path.resolve(__dirname, '../dll/dist/alpha.manifest.json'),
extensions: ['.js', '.ts'],
}),
new rspack.DllReferencePlugin({
manifest: path.resolve(__dirname, '../dll/dist/beta.manifest.json'),
scope: 'beta',
extensions: [".js", ".jsx", '.ts', '.tsx']
}),
],
mode: 'development'
}

module.exports = config;
1 change: 1 addition & 0 deletions rspack/dll/a.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "a";
1 change: 1 addition & 0 deletions rspack/dll/alpha.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "alpha";
1 change: 1 addition & 0 deletions rspack/dll/b.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "b";
1 change: 1 addition & 0 deletions rspack/dll/beta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "beta"
1 change: 1 addition & 0 deletions rspack/dll/c.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "c.tsx";
16 changes: 16 additions & 0 deletions rspack/dll/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "example-dll-plugin",
"private": true,
"scripts": {
"dev": "rspack serve",
"build": "rspack build || echo 'make-ci-happy'"
},
"dependencies": {
"lodash": "4.17.21"
},
"devDependencies": {
"@rspack/cli": "1.1.1",
"@rspack/core": "1.1.1",
"typescript": "^5.3.3"
}
}
27 changes: 27 additions & 0 deletions rspack/dll/rspack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

const rspack = require('@rspack/core')
const path = require('node:path');

/** @type {import('@rspack/cli').Configuration} */
const config = {
resolve: {
extensions: ['...', '.ts', '.tsx', '.js', '.jsx'],
},
entry: {
alpha: ["./alpha", "./a", "lodash"],
beta: ["./beta", "./b", "./c"],
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].dll.js',
library: '[name]_dll_lib'
},
plugins: [
new rspack.DllPlugin({
path: path.join(__dirname, "dist", "[name].manifest.json"),
name: '[name]_dll_lib',
})
]
}

module.exports = config;

0 comments on commit 36a148d

Please sign in to comment.