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/chatty-flies-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/web-platform-rsbuild-plugin": patch
---

Fix build on Windows
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// Copyright 2025 The Lynx Authors. All rights reserved.
// 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 { pathToFileURL } from 'node:url';

import type { LoaderContext } from 'webpack';

interface NativeModulesLoaderOptions {
Expand All @@ -12,7 +18,9 @@ export default function(
const { nativeModulesPath } = options;
const modifiedSource = source.replace(
/\/\* LYNX_NATIVE_MODULES_IMPORT \*\//g,
`import CUSTOM_NATIVE_MODULES from '${nativeModulesPath}';`,
`import CUSTOM_NATIVE_MODULES from ${
JSON.stringify(pathToFileURL(nativeModulesPath))
};`,
).replace(
/\/\* LYNX_NATIVE_MODULES_ADD \*\//g,
`Object.entries(CUSTOM_NATIVE_MODULES).map(([moduleName, moduleFunc]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
// 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 path from 'node:path';
import { fileURLToPath } from 'node:url';

import type { RsbuildPlugin } from '@rsbuild/core';
import path from 'path';

const __filename = new URL('', import.meta.url).pathname;
const __dirname = path.dirname(__filename);
const __dirname = path.dirname(fileURLToPath(import.meta.url));

/**
* The options for {@link pluginWebPlatform}.
Expand Down Expand Up @@ -88,17 +89,13 @@ export function pluginWebPlatform(
});

api.modifyRspackConfig(rspackConfig => {
console.log(path.resolve(
__dirname,
'./loaders/native-modules.js',
));
rspackConfig.module = {
...rspackConfig.module,
rules: [
...(rspackConfig.module?.rules ?? []),
{
test:
/backgroundThread\/background-apis\/createNativeModules\.js$/,
/backgroundThread[\\/]background-apis[\\/]createNativeModules\.js$/,
loader: path.resolve(
__dirname,
'./loaders/native-modules.js',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ describe('Bundle Build', () => {
for (const m of modules) {
if (
m.type === 'javascript/auto'
&& m.userRequest.includes('tests/fixtures/index.native-modules.ts')
&& m.userRequest.includes(
'tests/fixtures/index.native-modules.ts'.replaceAll('/', path.sep),
)
) {
if (!i.isOnlyInitial()) {
asyncChunkImportCount++;
Expand Down
Loading