Skip to content

Commit

Permalink
refactor!: remove service-worker target (#2657)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Jun 21, 2024
1 parent 18eaef2 commit 7a1e461
Show file tree
Hide file tree
Showing 30 changed files with 30 additions and 353 deletions.
60 changes: 0 additions & 60 deletions examples/service-worker/index.html

This file was deleted.

13 changes: 0 additions & 13 deletions examples/service-worker/package.json

This file was deleted.

15 changes: 0 additions & 15 deletions examples/service-worker/rsbuild.config.ts

This file was deleted.

21 changes: 0 additions & 21 deletions examples/service-worker/src/sw.ts

This file was deleted.

132 changes: 1 addition & 131 deletions packages/compat/plugin-swc/tests/__snapshots__/plugin.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -646,136 +646,6 @@ exports[`plugin-swc > should disable react refresh when target is not web 1`] =
`;

exports[`plugin-swc > should disable react refresh when target is not web 2`] = `
{
"rules": [
{
"include": [
{
"and": [
"<ROOT>/packages/compat/plugin-swc/tests",
{
"not": /\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]/,
},
],
},
/\\\\\\.\\(\\?:ts\\|tsx\\|jsx\\|mts\\|cts\\)\\$/,
],
"test": /\\\\\\.\\(\\?:js\\|jsx\\|mjs\\|cjs\\|ts\\|tsx\\|mts\\|cts\\)\\$/,
"use": [
{
"loader": "<ROOT>/packages/compat/plugin-swc/src/loader.cjs",
"options": {
"cwd": "<ROOT>/packages/compat/plugin-swc/tests",
"env": {
"coreJs": "3.36",
"mode": "usage",
"targets": [
"chrome >= 87",
"edge >= 88",
"firefox >= 78",
"safari >= 14",
],
},
"extensions": {
"lockCorejsVersion": {
"corejs": "<ROOT>/node_modules/<PNPM_INNER>/core-js",
"swcHelpers": "<ROOT>/node_modules/<PNPM_INNER>/@swc/helpers",
},
"lodash": {
"cwd": "<ROOT>/packages/compat/plugin-swc/tests",
"ids": [
"lodash",
"lodash-es",
],
},
},
"jsc": {
"externalHelpers": true,
"parser": {
"decorators": true,
"syntax": "typescript",
"tsx": true,
},
"preserveAllComments": true,
"transform": {
"decoratorMetadata": true,
"legacyDecorator": true,
"react": {
"refresh": false,
"runtime": "classic",
},
"useDefineForClassFields": false,
},
},
},
},
],
},
{
"mimetype": {
"or": [
"text/javascript",
"application/javascript",
],
},
"resolve": {
"fullySpecified": false,
},
"use": [
{
"loader": "<ROOT>/packages/compat/plugin-swc/src/loader.cjs",
"options": {
"cwd": "<ROOT>/packages/compat/plugin-swc/tests",
"env": {
"coreJs": "3.36",
"mode": "usage",
"targets": [
"chrome >= 87",
"edge >= 88",
"firefox >= 78",
"safari >= 14",
],
},
"extensions": {
"lockCorejsVersion": {
"corejs": "<ROOT>/node_modules/<PNPM_INNER>/core-js",
"swcHelpers": "<ROOT>/node_modules/<PNPM_INNER>/@swc/helpers",
},
"lodash": {
"cwd": "<ROOT>/packages/compat/plugin-swc/tests",
"ids": [
"lodash",
"lodash-es",
],
},
},
"jsc": {
"externalHelpers": true,
"parser": {
"decorators": true,
"syntax": "typescript",
"tsx": true,
},
"preserveAllComments": true,
"transform": {
"decoratorMetadata": true,
"legacyDecorator": true,
"react": {
"refresh": false,
"runtime": "classic",
},
"useDefineForClassFields": false,
},
},
},
},
],
},
],
}
`;

exports[`plugin-swc > should disable react refresh when target is not web 3`] = `
{
"rules": [
{
Expand Down Expand Up @@ -905,7 +775,7 @@ exports[`plugin-swc > should disable react refresh when target is not web 3`] =
}
`;

exports[`plugin-swc > should disable react refresh when target is not web 4`] = `
exports[`plugin-swc > should disable react refresh when target is not web 3`] = `
{
"rules": [
{
Expand Down
5 changes: 0 additions & 5 deletions packages/compat/plugin-swc/tests/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,6 @@ describe('plugin-swc', () => {
target: 'node',
},
},
serviceWorker: {
output: {
target: 'service-worker',
},
},
web: {
output: {
target: 'web',
Expand Down
1 change: 0 additions & 1 deletion packages/compat/webpack/src/webpackConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ async function getChainUtils(
web: 'client',
node: 'server',
'web-worker': 'web-worker',
'service-worker': 'service-worker',
};

return {
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
MEDIA_DIST_DIR,
ROOT_DIST_DIR,
SERVER_DIST_DIR,
SERVICE_WORKER_DIST_DIR,
SVG_DIST_DIR,
TS_CONFIG_FILE,
WASM_DIST_DIR,
Expand Down Expand Up @@ -140,7 +139,6 @@ const getDefaultOutputConfig = (): NormalizedOutputConfig => ({
image: IMAGE_DIST_DIR,
media: MEDIA_DIST_DIR,
server: SERVER_DIST_DIR,
worker: SERVICE_WORKER_DIST_DIR,
},
assetPrefix: DEFAULT_ASSET_PREFIX,
filename: {},
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type { RsbuildTarget } from '@rsbuild/shared';
export const ROOT_DIST_DIR = 'dist';
export const HTML_DIST_DIR = '/';
export const SERVER_DIST_DIR = 'server';
export const SERVICE_WORKER_DIST_DIR = 'worker';
export const JS_DIST_DIR = 'static/js';
export const CSS_DIST_DIR = 'static/css';
export const SVG_DIST_DIR = 'static/svg';
Expand Down Expand Up @@ -59,5 +58,4 @@ export const TARGET_ID_MAP: Record<RsbuildTarget, string> = {
web: 'Client',
node: 'Server',
'web-worker': 'Web Worker',
'service-worker': 'Service Worker',
};
37 changes: 17 additions & 20 deletions packages/core/src/plugins/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,28 @@ export const pluginEntry = (): RsbuildPlugin => ({
name: 'rsbuild:entry',

setup(api) {
api.modifyBundlerChain(
async (chain, { environment, isServer, isServiceWorker }) => {
const config = api.getNormalizedConfig({ environment });
const { preEntry } = config.source;
const { entry } = api.context.environments[environment];
api.modifyBundlerChain(async (chain, { environment, isServer }) => {
const config = api.getNormalizedConfig({ environment });
const { preEntry } = config.source;
const { entry } = api.context.environments[environment];

const injectCoreJsEntry =
config.output.polyfill === 'entry' && !isServer && !isServiceWorker;
const injectCoreJsEntry = config.output.polyfill === 'entry' && !isServer;

for (const entryName of Object.keys(entry)) {
const entryPoint = chain.entry(entryName);
const addEntry = (item: string | EntryDescription) => {
entryPoint.add(item);
};
for (const entryName of Object.keys(entry)) {
const entryPoint = chain.entry(entryName);
const addEntry = (item: string | EntryDescription) => {
entryPoint.add(item);
};

preEntry.forEach(addEntry);
preEntry.forEach(addEntry);

if (injectCoreJsEntry) {
addEntry(createVirtualModule('import "core-js";'));
}

castArray(entry[entryName]).forEach(addEntry);
if (injectCoreJsEntry) {
addEntry(createVirtualModule('import "core-js";'));
}
},
);

castArray(entry[entryName]).forEach(addEntry);
}
});

api.onBeforeCreateCompiler(({ bundlerConfigs }) => {
if (bundlerConfigs.every((config) => !config.entry)) {
Expand Down
12 changes: 1 addition & 11 deletions packages/core/src/plugins/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ export const pluginOutput = (): RsbuildPlugin => ({

setup(api) {
api.modifyBundlerChain(
async (
chain,
{ CHAIN_ID, target, isProd, isServer, isServiceWorker, environment },
) => {
async (chain, { CHAIN_ID, target, isProd, isServer, environment }) => {
const config = api.getNormalizedConfig({ environment });

const publicPath = getPublicPath({
Expand Down Expand Up @@ -114,13 +111,6 @@ export const pluginOutput = (): RsbuildPlugin => ({
});
}

if (isServiceWorker) {
const workerPath = config.output.distPath.worker;
const filename = posix.join(workerPath, '[name].js');

chain.output.filename(filename).chunkFilename(filename);
}

if (config.output.copy && api.context.bundlerType === 'rspack') {
const { copy } = config.output;
const options = Array.isArray(copy) ? { patterns: copy } : copy;
Expand Down
Loading

0 comments on commit 7a1e461

Please sign in to comment.