Skip to content

Commit c00525a

Browse files
authored
feat: basic support of asset bundleless (#221)
1 parent 31c6fc9 commit c00525a

File tree

23 files changed

+884
-23
lines changed

23 files changed

+884
-23
lines changed

.changeset/good-fishes-retire.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@rslib/core': patch
3+
---
4+
5+
realease

e2e/assets/image.png

174 KB
Loading

e2e/assets/logo.svg

Lines changed: 7 additions & 0 deletions
Loading

e2e/cases/banner-footer/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import './index.css';
1+
// import './index.css';
22
import { foo } from './foo';
33

44
export const text = foo;
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`svgr in bundleless 1`] = `
4+
"import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from \\"react/jsx-runtime\\";
5+
import \\"react\\";
6+
const SvgLogo = (props)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(\\"svg\\", {
7+
xmlns: \\"http://www.w3.org/2000/svg\\",
8+
viewBox: \\"0 0 841.9 595.3\\",
9+
...props,
10+
children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(\\"g\\", {
11+
fill: \\"#61DAFB\\",
12+
children: [
13+
/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(\\"path\\", {
14+
d: \\"M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3m-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9m-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9m32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1M421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32m-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24q7.05 12 14.4 23.4M420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32m-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9m-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6s22.9-35.6 58.3-50.6c8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2M310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7m237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1m38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6M320.8 78.4\\"
15+
}),
16+
/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(\\"circle\\", {
17+
cx: 420.9,
18+
cy: 296.5,
19+
r: 45.7
20+
}),
21+
/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(\\"path\\", {
22+
d: \\"M520.5 78.1\\"
23+
})
24+
]
25+
})
26+
});
27+
/* harmony default export */ const logoreact = SvgLogo;
28+
/* harmony default export */ const src = logoreact;
29+
export { src as default };
30+
"
31+
`;
32+
33+
exports[`svgr in bundleless 2`] = `
34+
"\\"use strict\\";
35+
// The require scope
36+
var __webpack_require__ = {};
37+
/************************************************************************/ // webpack/runtime/define_property_getters
38+
(()=>{
39+
__webpack_require__.d = function(exports1, definition) {
40+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
41+
enumerable: true,
42+
get: definition[key]
43+
});
44+
};
45+
})();
46+
// webpack/runtime/has_own_property
47+
(()=>{
48+
__webpack_require__.o = function(obj, prop) {
49+
return Object.prototype.hasOwnProperty.call(obj, prop);
50+
};
51+
})();
52+
// webpack/runtime/make_namespace_object
53+
(()=>{
54+
// define __esModule on exports
55+
__webpack_require__.r = function(exports1) {
56+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
57+
value: 'Module'
58+
});
59+
Object.defineProperty(exports1, '__esModule', {
60+
value: true
61+
});
62+
};
63+
})();
64+
/************************************************************************/ var __webpack_exports__ = {};
65+
// ESM COMPAT FLAG
66+
__webpack_require__.r(__webpack_exports__);
67+
// EXPORTS
68+
__webpack_require__.d(__webpack_exports__, {
69+
default: ()=>/* binding */ src
70+
});
71+
const jsx_runtime_namespaceObject = require(\\"react/jsx-runtime\\");
72+
require(\\"react\\");
73+
const SvgLogo = (props)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(\\"svg\\", {
74+
xmlns: \\"http://www.w3.org/2000/svg\\",
75+
viewBox: \\"0 0 841.9 595.3\\",
76+
...props,
77+
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(\\"g\\", {
78+
fill: \\"#61DAFB\\",
79+
children: [
80+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(\\"path\\", {
81+
d: \\"M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3m-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9m-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9m32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1M421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32m-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24q7.05 12 14.4 23.4M420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32m-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9m-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6s22.9-35.6 58.3-50.6c8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2M310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7m237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1m38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6M320.8 78.4\\"
82+
}),
83+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(\\"circle\\", {
84+
cx: 420.9,
85+
cy: 296.5,
86+
r: 45.7
87+
}),
88+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(\\"path\\", {
89+
d: \\"M520.5 78.1\\"
90+
})
91+
]
92+
})
93+
});
94+
/* harmony default export */ const logoreact = SvgLogo;
95+
/* harmony default export */ const src = logoreact;
96+
var __webpack_export_target__ = exports;
97+
for(var i in __webpack_exports__)__webpack_export_target__[i] = __webpack_exports__[i];
98+
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
99+
value: true
100+
});
101+
"
102+
`;

e2e/cases/bundle-false/relative-import/package.json renamed to e2e/cases/bundle-false/asset/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "bundle-false-relative-import-test",
2+
"name": "bundle-false-asset-test",
33
"version": "1.0.0",
44
"private": true,
55
"type": "module"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper';
2+
import { defineConfig } from '@rslib/core';
3+
4+
export default defineConfig({
5+
lib: [
6+
generateBundleEsmConfig({
7+
bundle: false,
8+
}),
9+
generateBundleCjsConfig({
10+
bundle: false,
11+
}),
12+
],
13+
// do not inline svg
14+
output: {
15+
dataUriLimit: {
16+
svg: 0,
17+
},
18+
},
19+
source: {
20+
entry: {
21+
index: ['./src/**'],
22+
},
23+
},
24+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import image from '../../../../assets/image.png';
2+
import logoURL from '../../../../assets/logo.svg';
3+
4+
console.log(logoURL);
5+
console.log(image);

e2e/cases/bundle-false/index.test.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ test('single file', async () => {
4040
`);
4141
});
4242

43-
test('auto add extension for relative import', async () => {
44-
const fixturePath = join(__dirname, 'relative-import');
43+
test('auto add js extension for relative import', async () => {
44+
const fixturePath = join(__dirname, 'js-extension');
4545
const { contents } = await buildAndGetResults(fixturePath);
4646

4747
for (const importer of [
@@ -62,3 +62,27 @@ test('auto add extension for relative import', async () => {
6262
expect(Object.values(contents.cjs)[3]).toContain(requirer);
6363
}
6464
});
65+
66+
test('asset in bundleless', async () => {
67+
const fixturePath = join(__dirname, 'asset');
68+
const { contents } = await buildAndGetResults(fixturePath);
69+
70+
const assets = [
71+
'const image_namespaceObject = __webpack_require__.p + "static/image/image.png";',
72+
'const logo_namespaceObject = __webpack_require__.p + "static/svg/logo.svg";',
73+
];
74+
75+
for (const asset of assets) {
76+
expect(Object.values(contents.esm)[0]).toContain(asset);
77+
expect(Object.values(contents.cjs)[0]).toContain(asset);
78+
}
79+
});
80+
81+
test('svgr in bundleless', async () => {
82+
const fixturePath = join(__dirname, 'svgr');
83+
const { contents } = await buildAndGetResults(fixturePath);
84+
85+
// TODO: import "react"; in output now, we should shake this
86+
expect(Object.values(contents.esm)[0]).toMatchSnapshot();
87+
expect(Object.values(contents.cjs)[0]).toMatchSnapshot();
88+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "bundle-false-js-extension-test",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module"
6+
}

0 commit comments

Comments
 (0)