alibaba / rax

🐰 Rax is a progressive framework for building universal application. https://rax.js.org
Other
7.99k stars 627 forks source link

怎么添加给webpack配置添加fullySpecified": false #2419

Closed Fhasghrge closed 6 months ago

Fhasghrge commented 7 months ago

问题:

Module not found: Error: Can't resolve './assets' in '/Users/xxx/@xxx/es2017'
Did you mean 'index.js'?
BREAKING CHANGE: The request './assets' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.

解决方案: 在build.json中配置如下,没有生效

{
"webpackLoaders": {
    "mjs": {
      "test": "/.m?js$/",
      "include": "/node_modules/",
      "type": "javascript/auto",
      "resolve": {
        "fullySpecified": false
      }
    }
  }
}

请问如何修改才能让 "fullySpecified": false生效

Fhasghrge commented 6 months ago
// build.plugin.js
module.exports = ({ context, onGetWebpackConfig }) => {
  onGetWebpackConfig((config) => {
    config.module
      .rule('esm')
      .test(/\.m?jsx?$/)
      .resolve.set('fullySpecified', false);
  });
};