Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/afraid-crews-dig.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/template-webpack-plugin": patch
---

feat: support elementTemplate for web
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export class WebEncodePlugin {
root: encodeOptions.lepusCode.root,
},
customSections: encodeOptions.customSections,
elementTemplate: encodeOptions['elementTemplate'],
})),
debugInfo: '',
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.info('**aaa**');
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/// <reference types="vitest/globals" />

import * as path from 'node:path';
import * as fs from 'node:fs/promises';

it('should have elementTemplate', async () => {
const fileContent = (await fs.readFile(
path.join(__dirname, '..', '.rspeedy', 'a', 'tasm.json'),
))
.toString();
const { elementTemplate } = JSON.parse(fileContent);
expect(elementTemplate).toBeTruthy();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { LynxTemplatePlugin, WebEncodePlugin } from '../../../../src';

/** @type {import('@rspack/core').Configuration} */
export default {
entry: {
a: './a.js',
b: './b.js',
'a:main-thread': { import: './a.js', filename: 'a/a.lepus.js' },
'b:main-thread': { import: './b.js', filename: 'b/b.lepus.js' },
},
context: __dirname,
output: {
filename: '[name]/[name].js',
},
plugins: [
new WebEncodePlugin({
include: [/a.js/g],
}),
new LynxTemplatePlugin({
...LynxTemplatePlugin.defaultOptions,
chunks: ['a', 'a:main-thread'],
filename: 'a/template.js',
intermediate: '.rspeedy/a',
}),

compiler => {
compiler.hooks.thisCompilation.tap('test', (compilation) => {
compilation.hooks.processAssets.tap('test', () => {
['a'].forEach(name => {
const asset = compilation.getAsset(`${name}/${name}.js`);
compilation.updateAsset(asset.name, asset.source, {
...asset.info,
'lynx:main-thread': true,
});
});
});
compilation.hooks.processAssets.tap(
{
name: 'element-template-test',
stage:
compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_PRE_PROCESS,
},
() => {
const hooks = LynxTemplatePlugin.getLynxTemplatePluginHooks(
// @ts-expect-error compilation is compatible with webpack
compilation,
);
hooks.beforeEncode.tap('element-template-test', (args) => {
args.encodeData.elementTemplate = {};
return args;
});
},
);
});
},
],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import("@lynx-js/test-runner").TConfigCaseConfig} */
module.exports = {
bundlePath: [
'b/b.js',
],
};
Loading