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

chore: polish code #32

Merged
merged 1 commit into from
Feb 21, 2024
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
8 changes: 1 addition & 7 deletions examples/vue/modern.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { appTools, defineConfig } from '@modern-js/app-tools';
import { isDev, webxPlugin } from '@webx-kit/modernjs-plugin';
import { webxPlugin } from '@webx-kit/modernjs-plugin';
import { builderPluginVue } from '@modern-js/builder-plugin-vue';

// https://modernjs.dev/en/configure/app/usage
Expand All @@ -12,12 +12,6 @@ export default defineConfig({
}),
],
builderPlugins: [builderPluginVue()],
source: {
define: {
// TODO: remove next line after https://github.com/web-infra-dev/modern.js/pull/5185 is merged
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: JSON.stringify(false),
},
},
output: {
copy: [
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"engines": {
"node": ">=18"
},
"packageManager": "pnpm@8.15.1",
"packageManager": "pnpm@8.15.3",
"scripts": {
"lint:type": "turbo lint:type",
"build": "turbo build",
Expand Down
18 changes: 6 additions & 12 deletions packages/modernjs-plugin/src/plugins/background/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { webpack as webpackNS } from '@modern-js/app-tools';
import { isDev, type WebpackChain } from '@modern-js/utils';
import { RsbuildPlugin } from '@rsbuild/shared';
import { BackgroundReloadPlugin } from './live-reload-plugin';

Expand Down Expand Up @@ -38,16 +36,12 @@ export const backgroundPlugin = ({ background, backgroundLiveReload = true }: Ba
const entry: BackgroundEntry =
typeof background === 'string' ? { name: DEFAULT_BACKGROUND_NAME, import: background } : background;

api.modifyWebpackChain((chain: WebpackChain) => {
chain.entryPoints.set(entry.name, {
values: () =>
({
import: entry.import,
library: { type: 'module' },
} satisfies webpackNS.EntryObject[string]),
} as any);

if (isDev())
api.modifyWebpackChain((chain, { isProd }) => {
chain.entry(entry.name).add({
import: entry.import,
library: { type: 'module' },
});
if (!isProd)
chain.plugin('BackgroundReloadPlugin').use(BackgroundReloadPlugin, [entry.name, backgroundLiveReload]);
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,10 @@ function patchLoadScriptRuntimeModule(
module.generate = function (this: webpackNS.RuntimeModule) {
return webpack.Template.asString([
// jsonp will cause cross-context issues in the isolated content-script environment
`${RuntimeGlobals.loadScript} = async function (url, done, key, chunkId) {
`${RuntimeGlobals.loadScript} = async function (url, done) {
await import(url);
done(null);
};`,

`
window.location.reload = () => { debugger; }
`,
]);
};
}
5 changes: 2 additions & 3 deletions packages/modernjs-plugin/src/plugins/content-scripts/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { WebpackChain, isDev } from '@modern-js/utils';
import { RsbuildPlugin } from '@rsbuild/shared';
import { ContentScriptHMRPlugin } from './hmr-plugin';
import { ContentScriptPublicPathPlugin } from './public-path-plugin';
Expand Down Expand Up @@ -33,11 +32,11 @@ export const contentScriptsPlugin = ({ contentScripts }: ContentScriptsOptions):
? contentScripts
: [{ name: DEFAULT_CONTENT_SCRIPT_NAME, import: contentScripts }];

api.modifyWebpackChain((chain: WebpackChain) => {
api.modifyWebpackChain((chain, { isProd }) => {
entries.forEach((entry) => chain.entry(entry.name).add(entry.import));

const contentScriptNames = new Set(getContentScriptEntryNames({ contentScripts }));
if (isDev()) {
if (!isProd) {
chain.plugin('ContentScriptHMRPlugin').use(ContentScriptHMRPlugin, [contentScriptNames]);
chain.plugin('ContentScriptShadowRootPlugin').use(ContentScriptShadowRootPlugin, [contentScriptNames]);
} else {
Expand Down
Loading