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
7 changes: 7 additions & 0 deletions .changeset/eighty-snails-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@lynx-js/template-webpack-plugin": patch
---

Add `WebEncodePlugin`.

This is previously known as `WebWebpackPlugin` from `@lynx-js/web-webpack-plugin`.
1 change: 0 additions & 1 deletion .changeset/forty-garlics-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"@lynx-js/css-extract-webpack-plugin": patch
"@lynx-js/react-refresh-webpack-plugin": patch
"@lynx-js/react-webpack-plugin": patch
"@lynx-js/web-webpack-plugin": patch
---

Support `@lynx-js/template-webpack-plugin` v0.7.0.
5 changes: 5 additions & 0 deletions .changeset/solid-ears-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/react-rsbuild-plugin": patch
---

Use `WebEncodePlugin` instead of `WebWebpackPlugin`.
1 change: 0 additions & 1 deletion packages/rspeedy/plugin-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"@lynx-js/react-webpack-plugin": "workspace:*",
"@lynx-js/runtime-wrapper-webpack-plugin": "workspace:*",
"@lynx-js/template-webpack-plugin": "workspace:*",
"@lynx-js/web-webpack-plugin": "workspace:*",
"background-only": "workspace:^"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/rspeedy/plugin-react/src/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import {
CSSPlugins,
LynxEncodePlugin,
LynxTemplatePlugin,
WebEncodePlugin,
} from '@lynx-js/template-webpack-plugin'
import { WebWebpackPlugin } from '@lynx-js/web-webpack-plugin'

import type { PluginReactLynxOptions } from './pluginReactLynx.js'

Expand Down Expand Up @@ -234,7 +234,7 @@ export function applyEntry(
if (isWeb) {
chain
.plugin(PLUGIN_NAME_WEB)
.use(WebWebpackPlugin, [])
.use(WebEncodePlugin, [])
.end()
}

Expand Down
8 changes: 4 additions & 4 deletions packages/rspeedy/plugin-react/test/web.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import { createRsbuild } from '@rsbuild/core'
import { describe, expect, test } from 'vitest'

import { WebEncodePlugin } from '@lynx-js/template-webpack-plugin'
import type { LynxTemplatePlugin } from '@lynx-js/template-webpack-plugin'
import { WebWebpackPlugin } from '@lynx-js/web-webpack-plugin'

import { pluginStubRspeedyAPI } from './stub-rspeedy-api.plugin.js'

Expand Down Expand Up @@ -126,19 +126,19 @@ describe('Web', () => {

expect(
lynxConfig?.plugins?.some(p =>
p?.constructor.name === WebWebpackPlugin.name
p?.constructor.name === WebEncodePlugin.name
),
).toBeFalsy()

expect(
webConfig?.plugins?.some(p =>
p?.constructor.name === WebWebpackPlugin.name
p?.constructor.name === WebEncodePlugin.name
),
).toBeTruthy()

expect(
prefetchConfig?.plugins?.some(p =>
p?.constructor.name === WebWebpackPlugin.name
p?.constructor.name === WebEncodePlugin.name
),
).toBeFalsy()
})
Expand Down
1 change: 0 additions & 1 deletion packages/rspeedy/plugin-react/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
{ "path": "../../webpack/template-webpack-plugin/tsconfig.build.json" },
{ "path": "../../webpack/react-webpack-plugin/tsconfig.build.json" },
{ "path": "../../webpack/react-refresh-webpack-plugin/tsconfig.build.json" },
{ "path": "../../webpack/web-webpack-plugin/tsconfig.json" },
{ "path": "../core/tsconfig.build.json" },
{ "path": "../plugin-react-alias/tsconfig.build.json" },
],
Expand Down
1 change: 0 additions & 1 deletion packages/rspeedy/plugin-react/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
{ "path": "../../webpack/template-webpack-plugin/tsconfig.build.json" },
{ "path": "../../webpack/react-webpack-plugin/tsconfig.build.json" },
{ "path": "../../webpack/react-refresh-webpack-plugin/tsconfig.build.json" },
{ "path": "../../webpack/web-webpack-plugin/tsconfig.json" },
{ "path": "../core/tsconfig.build.json" },
{ "path": "../plugin-react-alias/tsconfig.build.json" },
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,23 @@ export interface TemplateHooks {
}>;
}

// Warning: (ae-missing-release-tag) "WebEncodePlugin" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export class WebEncodePlugin {
// (undocumented)
apply(compiler: Compiler): void;
// (undocumented)
static BEFORE_ENCODE_HOOK_STAGE: number;
deleteDebuggingAssets(compilation: Compilation, assets: ({
name: string;
} | undefined)[]): void;
// (undocumented)
static ENCODE_HOOK_STAGE: number;
// (undocumented)
static name: string;
}

// Warnings were encountered during analysis:
//
// lib/LynxTemplatePlugin.d.ts:58:9 - (ae-forgotten-export) The symbol "EncodeRawData" needs to be exported by the entry point index.d.ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

import type { Compilation, Compiler } from 'webpack';

import { LynxTemplatePlugin } from '@lynx-js/template-webpack-plugin';

import { genStyleInfo } from './style/genStyleInfo.js';

export class WebWebpackPlugin {
static name = 'lynx-for-web-plugin';
import {
LynxTemplatePlugin,
isDebug,
isRsdoctor,
} from './LynxTemplatePlugin.js';
import { genStyleInfo } from './web/genStyleInfo.js';

export class WebEncodePlugin {
static name = 'WebEncodePlugin';
static BEFORE_ENCODE_HOOK_STAGE = 100;
static ENCODE_HOOK_STAGE = 100;

Expand All @@ -18,7 +21,7 @@ export class WebWebpackPlugin {
|| compiler.options.mode === 'development';

compiler.hooks.thisCompilation.tap(
WebWebpackPlugin.name,
WebEncodePlugin.name,
(compilation) => {
const hooks = LynxTemplatePlugin.getLynxTemplatePluginHooks(
compilation,
Expand All @@ -28,7 +31,7 @@ export class WebWebpackPlugin {

const { Compilation } = compiler.webpack;
compilation.hooks.processAssets.tap({
name: WebWebpackPlugin.name,
name: WebEncodePlugin.name,

// `PROCESS_ASSETS_STAGE_REPORT` is the last stage of the `processAssets` hook.
// We need to run our asset deletion after this stage to ensure all assets have been processed.
Expand All @@ -42,8 +45,8 @@ export class WebWebpackPlugin {
});

hooks.beforeEncode.tap({
name: WebWebpackPlugin.name,
stage: WebWebpackPlugin.BEFORE_ENCODE_HOOK_STAGE,
name: WebEncodePlugin.name,
stage: WebEncodePlugin.BEFORE_ENCODE_HOOK_STAGE,
}, (encodeOptions) => {
const { encodeData } = encodeOptions;
const { cssMap } = encodeData.css;
Expand Down Expand Up @@ -76,8 +79,8 @@ export class WebWebpackPlugin {
});

hooks.encode.tap({
name: WebWebpackPlugin.name,
stage: WebWebpackPlugin.ENCODE_HOOK_STAGE,
name: WebEncodePlugin.name,
stage: WebEncodePlugin.ENCODE_HOOK_STAGE,
}, ({ encodeOptions }) => {
return {
buffer: Buffer.from(JSON.stringify({
Expand Down Expand Up @@ -115,24 +118,6 @@ export class WebWebpackPlugin {
}
}

export function isDebug(): boolean {
if (!process.env['DEBUG']) {
return false;
}

const values = process.env['DEBUG'].toLocaleLowerCase().split(',');
return [
'rspeedy',
'*',
'rspeedy:*',
'rspeedy:template',
].some((key) => values.includes(key));
}

export function isRsdoctor(): boolean {
return process.env['RSDOCTOR'] === 'true';
}

function last<T>(array: T[]): T | undefined {
return array[array.length - 1];
}
1 change: 1 addition & 0 deletions packages/webpack/template-webpack-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ export type {
LynxEncodePluginOptions,
EncodeCSSOptions,
} from './LynxEncodePlugin.js';
export { WebEncodePlugin } from './WebEncodePlugin.js';
export * as CSSPlugins from './css/plugins/index.js';
export * as CSS from './css/index.js';
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.

// LICENSE file in the root directory of this source tree.
export interface CSSRule {
sel: string[][][];
decl: [string, string][];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.

import { CSS } from '@lynx-js/template-webpack-plugin';

import type { CSSRule, OneInfo, StyleInfo } from '../type/StyleInfo.js';
import type { CSSRule, OneInfo, StyleInfo } from './StyleInfo.js';
import * as CSS from '../css/index.js';

export function genStyleInfo(
cssMap: Record<string, CSS.LynxStyleNode[]>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { LynxTemplatePlugin } from '@lynx-js/template-webpack-plugin';
import { WebWebpackPlugin } from '../../../../src';
import { LynxTemplatePlugin, WebEncodePlugin } from '../../../../src';

/** @type {import('@rspack/core').Configuration} */
export default {
Expand All @@ -14,7 +13,7 @@ export default {
filename: '[name]/[name].js',
},
plugins: [
new WebWebpackPlugin({
new WebEncodePlugin({
include: [/a.js/g],
cardType: 'react',
allInOne: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { LynxTemplatePlugin } from '@lynx-js/template-webpack-plugin';
import { WebWebpackPlugin } from '../../../../src';
import { LynxTemplatePlugin, WebEncodePlugin } from '../../../../src';

/** @type {import('@rspack/core').Configuration} */
export default {
Expand All @@ -14,7 +13,7 @@ export default {
filename: '[name]/[name].js',
},
plugins: [
new WebWebpackPlugin({
new WebEncodePlugin({
include: [/a.js/g],
}),
new LynxTemplatePlugin({
Expand Down
1 change: 0 additions & 1 deletion packages/webpack/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
{ "path": "./runtime-wrapper-webpack-plugin/tsconfig.build.json" },
{ "path": "./webpack-dev-transport/tsconfig.build.json" },
{ "path": "./template-webpack-plugin/tsconfig.build.json" },
{ "path": "./web-webpack-plugin/tsconfig.json" },
{ "path": "./react-webpack-plugin/tsconfig.build.json" },
{ "path": "./css-extract-webpack-plugin/tsconfig.build.json" },
{ "path": "./react-refresh-webpack-plugin/tsconfig.build.json" },
Expand Down
Loading
Loading