-
-
Notifications
You must be signed in to change notification settings - Fork 595
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
[Bug]:v0.6.4 配置namedExports无效 #6339
Comments
按理来说,rsbuild 默认设置下 0.5.9 rsbuild 默认设置下你需要使用 另外修改 rspack 配置字段是 |
修改了配置后,codesandbox的确没法复现问题了。本地的less文件是node_modules中的一个依赖(通过cssModules.auto将此依赖包下的所有less文件均做cssModule处理),是否是此原因导致的? |
的确是因为less文件在node_modules中的原因,codesandbox已更新 node_modules中的依赖包源码: |
使用的是 |
不好意思看岔了,这里是 require...确实应该有 我觉得是个 bug。 @chenjiahan 请帮忙转到 rspack 。 Issuerspack.config.jsmodule.exports = {
module: {
parser: {
'css/module': { namedExports: false }
},
rules: [{ test: /\.css$/, type: 'css/module' }]
},
} As per doc, when When importing a css module with import * as S from './style.module.css';
console.log(S); // Module { default: Module {foo: "a"}, foo: "a", __esModule: true } While importing a css module with const S = require('./style.module.css');
console.log(S); // Module { foo: "a", __esModule: true }
// the `default` field is missing |
done👌 |
虽然这里配置了 var _style = _interopRequireDefault(require("./style.less"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 所以实际 Rspack 打包时读到的代码是这份 cjs,Rspack v0.5.9 能够正常工作是因为之前并没有给 css module 添加 v0.5.9 Object { test: "xxx (hash of the class name)" } v0.6+ Object {
__esModule: true, // <-- 注意这里
test: "xxx (hash of the class name)",
} 这就导致 但实际上 v0.5.9 的行为严格上来说并不正确,v0.6+ 默认添加 目前有以下方案:
|
@xc2 |
Rsbuild 近期会默认切换到 预计还需要 1~2 周进行测试验证 |
@NexxLuo 如果比较紧急的话可以用 bundlerChain 来临时使用,这里有一个最小的例子: import { defineConfig } from "@rsbuild/core";
export default defineConfig({
output: {
// 临时借用 injectStyle 这个配置项来自动配置 css-loader
injectStyles: true,
},
tools: {
bundlerChain(chain, { CHAIN_ID }) {
const coreRequire = require("node:module").createRequire(require.resolve("@rsbuild/core"));
const { CssExtractRspackPlugin } = require(coreRequire.resolve("@rspack/core"));
chain.plugin("--css-extract").use(CssExtractRspackPlugin, [{ /* plugin options */ }]);
for (const styleRuleId of [CHAIN_ID.RULE.CSS, CHAIN_ID.RULE.LESS, CHAIN_ID.RULE.SASS]) {
const rule = chain.module.rule(styleRuleId);
rule.uses.delete(CHAIN_ID.USE.STYLE);
rule.use("--css-extract").loader(CssExtractRspackPlugin.loader).before(CHAIN_ID.USE.CSS);
}
},
},
}); |
0.6.15版本是还没包含这个更改吗 |
0.7.0 会包含 |
I'm testing with latest release candidate
where offset is defined as Or is the solution expected to be used along with |
I was able to resolve the issue by setting
|
Version
Details
0.5.9一切运行正常,更新到0.6.4后,node_modules下的less文件均无法使用默认导出(报错
Cannot read properties of undefined (reading 'test')
) ,test
为less文件中的类名;参照0.6.0的发布文档,通过config.module.parser手动配置namedExports依然无效;
场景:
对node_modules中某一个包的less文件进行cssModule处理;
如codesandbox中的
nexx-test-less
,包中使用了less文件import styles from "./style.less"
Reproduce link
codesandbox
Reproduce Steps
访问上面的codesandbox库,查看控制台输出信息
The text was updated successfully, but these errors were encountered: