Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: overwrite document entry #1028

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions packages/plugin-rax-web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v2.0.9

- Fix: ssr overwrite document output

## v2.0.8

- Fix: build-scripts version
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-rax-web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-rax-web",
"version": "2.0.8",
"version": "2.0.9",
"description": "rax web app plugin",
"main": "lib/index.js",
"scripts": {
Expand Down
12 changes: 7 additions & 5 deletions packages/plugin-rax-web/src/Plugins/DocumentPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { registerListenTask, getAssets, getEnableStatus, updateEnableStatus } fr
import * as webpackSources from 'webpack-sources';
import { processAssets, emitAsset } from '@builder/compat-webpack4';
import { getInjectedHTML, getBuiltInHtmlTpl, insertCommonElements, genComboedScript } from '../utils/htmlStructure';
import { setDocument } from '../utils/document';
import { setDocument, getDocumentEntryName } from '../utils/document';
import { updateHTMLByEntryName } from '../utils/htmlCache';

const PLUGIN_NAME = 'DocumentPlugin';
Expand Down Expand Up @@ -70,10 +70,12 @@ export default class DocumentPlugin {
});
let html = '';
let customDocument = false;
const documentEntry = getDocumentEntryName(entryName);

// PHA will consume document field
if (documentPath && localBuildAssets[`${entryName}.js`]) {
if (documentPath && localBuildAssets[documentEntry]) {
customDocument = true;
const bundleContent = localBuildAssets[`${entryName}.js`].source();
const bundleContent = localBuildAssets[documentEntry].source();
const mod = exec(bundleContent, entryPath);

try {
Expand Down Expand Up @@ -102,9 +104,9 @@ export default class DocumentPlugin {
} else {
let initialHTML;

if (localBuildAssets[`${entryName}.js`]) {
if (localBuildAssets[documentEntry]) {
customDocument = true;
const bundleContent = localBuildAssets[`${entryName}.js`].source();
const bundleContent = localBuildAssets[documentEntry].source();
const mod = exec(bundleContent, entryPath);
try {
initialHTML = mod.renderPage();
Expand Down
4 changes: 3 additions & 1 deletion packages/plugin-rax-web/src/setLocalBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as chokidar from 'chokidar';
import LocalBuilderPlugin from './Plugins/LocalBuilderPlugin';
import { GET_RAX_APP_WEBPACK_CONFIG } from './constants';
import { updateEnableStatus } from './utils/localBuildCache';
import { getDocumentEntryName } from './utils/document';

export default (api, documentPath?: string | undefined) => {
const { onGetWebpackConfig, getValue, context, registerTask, registerUserConfig, modifyUserConfig } = api;
Expand Down Expand Up @@ -118,7 +119,8 @@ export default (api, documentPath?: string | undefined) => {
}
}

config.entry(entryName).add(
const documentEntry = getDocumentEntryName(entryName);
config.entry(documentEntry).add(
`${require.resolve('./Loaders/render-loader')}?${qs.stringify({
documentPath,
entryPath,
Expand Down
4 changes: 4 additions & 0 deletions packages/plugin-rax-web/src/utils/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ export function getDocument({ name, source }) {
}
return documentMap[entryName];
}

export function getDocumentEntryName(entryName: string) {
return `document_${entryName.split('/').join('_')}`;
}