rsbuild icon indicating copy to clipboard operation
rsbuild copied to clipboard

[Feature]: support `?raw` for ts

Open ouzhou opened this issue 1 year ago • 4 comments

What problem does this feature solve?

import LODASH_array from '@types/lodash/common/array.d.ts?raw';

I want to return a string

What does the proposed API look like?

As intuition suggests, any file should only return a string after concatenating this suffix The current situation is that this suffix function only supports files other than ts like 'txt' etc....

ouzhou avatar Sep 10 '24 08:09 ouzhou

you could try use tools.rspack or tools.bundlerChain to support resourceQuery like svgr plugin

https://rsbuild.dev/plugins/list/plugin-svgr#svgroptionsexporttype https://github.com/web-infra-dev/rsbuild/tree/main/packages/plugin-svgr

SoonIter avatar Sep 10 '24 08:09 SoonIter

see https://github.com/web-infra-dev/rsbuild/issues/3070

ouzhou avatar Sep 10 '24 09:09 ouzhou

could you add enforce: 'pre' to your rule? @ouzhou

SoonIter avatar Sep 10 '24 09:09 SoonIter

I tried all the parameters of enforce from the beginning

import str from "!./myType.ts?raw"; add ! can reslove this , but use ! is not a intuitive writing style

Without this feature, I find it difficult to migrate painlessly from vite https://vitejs.dev/guide/assets.html#importing-asset-as-string

ouzhou avatar Sep 10 '24 10:09 ouzhou

Image Image 我主动为“?raw”结尾的链接添加了“!”,折中的实现了和vite类似的效果

eatfishs avatar Oct 21 '24 08:10 eatfishs

This feature will be tracked here: https://github.com/web-infra-dev/rsbuild/issues/3778

Closed as duplicate.

chenjiahan avatar Nov 08 '24 03:11 chenjiahan