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

feat: support asset module #684

Merged
merged 3 commits into from
Jan 23, 2025
Merged

feat: support asset module #684

merged 3 commits into from
Jan 23, 2025

Conversation

SoonIter
Copy link
Member

@SoonIter SoonIter commented Jan 14, 2025

Summary

there are some cases to show the rslib asset/module artifect after this change

1. asset/resource

input

└── src
    ├── assets
    │   └── logo.svg   // <--
    └── index.tsx
// index.tsx
import foo from './assets/logo.svg';
console.log(foo);

output

./dist
└── esm
    ├── assets
    │   └── logo.mjs     // <-- default reexport from svg
    ├── static/svg
    │   └── logo.svg     // <--
    ├── index.d.ts
    └── index.mjs
// dist/esm/index.mjs
import foo from './assets/logo.mjs';
console.log(foo);
// dist/esm/assets/logo.mjs
import url from '../static/svg/logo.svg';
export { url as default };

2. asset/inline

decided by output.dataUriLimit

input

└── src
    ├── assets
    │   └── logo.svg   // <--
    └── index.tsx
// index.tsx
import foo from './assets/logo.svg';
console.log(foo);

output

./dist
└── esm
    ├── assets
    │   └── logo.mjs    // <-- default export a "data" url string
    ├── index.d.ts
    └── index.mjs
// dist/esm/index.mjs
import foo from './assets/logo.mjs';
console.log(foo);
// dist/esm/assets/logo.mjs
const url = "data:image/svg+xml;base64,foo"
export { url as default };

3. asset/source

input

└── src
    ├── assets
    │   └── logo.svg   // <--
    └── index.tsx
// index.tsx
import foo from './assets/logo.svg';
console.log(foo);

output

./dist
└── esm
    ├── assets
    │   └── logo.mjs    // <-- default export a source txt string
    ├── index.d.ts
    └── index.mjs
// dist/esm/index.mjs
import foo from './assets/logo.mjs';
console.log(foo);
// dist/esm/assets/logo.mjs
const url = "source text"
export { url as default };

4. svgr

queryImport is only supported in bundle, not supported in bundleless

we recommend that bundleless uses mixedImport

pluginSvgr({
	mixedImport: true
});

input

└── src
    ├── assets
    │   └── logo.svg   // <--
    └── index.tsx
// index.tsx
import foo from './assets/logo.svg';
console.log(foo);

output

./dist
└── esm
    ├── assets
    │   └── logo.mjs     // <-- both url and Svgr ReactComponent
    ├── index.d.ts
    └── index.mjs
// dist/esm/index.mjs
import foo from './assets/logo.mjs';
console.log(foo);
// dist/esm/assets/logo.mjs
import __rslib_svgr_url__0__ from "../static/svg/logo.svg";
import { jsx, jsxs } from "react/jsx-runtime";
import * as React from "react";
const SvgLogo = (props) => /* @__PURE__ */ jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 841.9 }) });
var logo_default = SvgLogo;
const logo_rslib_entry_ = __rslib_svgr_url__0__;
export { SvgLogo as ReactComponent, logo_rslib_entry_ as default };

5. publicPath

you can switch to old behavior (contain __webpack_require__.p) by set output.assetPrefix

default value of output.assetPrefix is "auto"

Related Links

close #570

associated with https://github.com/web-infra-dev/rspack/pull/8724/files#

close #219

close #230

close #231

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copy link

netlify bot commented Jan 14, 2025

Deploy Preview for rslib ready!

Name Link
🔨 Latest commit c4b6dac
🔍 Latest deploy log https://app.netlify.com/sites/rslib/deploys/6790c48db285fa0008d90c01
😎 Deploy Preview https://deploy-preview-684--rslib.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@SoonIter SoonIter changed the title feat: support asset feat: support asset by generator['asset'].experimentalLibPreserveImport Jan 15, 2025
@Timeless0911 Timeless0911 changed the title feat: support asset by generator['asset'].experimentalLibPreserveImport feat: support asset module Jan 15, 2025
@SoonIter SoonIter force-pushed the asset-support-rust branch 2 times, most recently from cafaf00 to 1682dac Compare January 16, 2025 15:52
packages/core/src/asset/assetConfig.ts Show resolved Hide resolved
packages/core/src/asset/assetConfig.ts Show resolved Hide resolved
packages/core/src/asset/assetConfig.ts Show resolved Hide resolved
packages/core/src/asset/assetConfig.ts Outdated Show resolved Hide resolved
packages/core/src/config.ts Show resolved Hide resolved
@SoonIter SoonIter force-pushed the asset-support-rust branch 2 times, most recently from fb2d90d to 8237684 Compare January 20, 2025 11:30
@Timeless0911 Timeless0911 merged commit 19dc930 into main Jan 23, 2025
17 checks passed
@Timeless0911 Timeless0911 deleted the asset-support-rust branch January 23, 2025 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants