alibaba / ice

🚀 ice.js: The Progressive App Framework Based On React(基于 React 的渐进式应用框架)
https://ice.work
MIT License
17.8k stars 2.09k forks source link

ice3.0通过模板快速创建的主应用无法正常导入二进制文件资源 #6887

Closed LOL871230823 closed 1 month ago

LOL871230823 commented 1 month ago

Describe the bug

npm init ice icestark-framework @icedesign/stark-layout

image image image

Expected behavior

希望可以想图片相关资源一样,可以正常导入

Actual behavior

No response

Version of ice.js

"@ice/app": "^3.0.0",

Content of build.json or ice.config.mts

import { defineConfig } from '@ice/app';
import icestark from '@ice/plugin-icestark';
import fusion from '@ice/plugin-fusion';
import store from '@ice/plugin-store';
import request from '@ice/plugin-request';
import { addLoader, modifyLoader, removeLoader } from '@ice/webpack-modify';
export default defineConfig(() => ({
  ssg: false,
  plugins: [
    fusion({
      themePackage: '@alifd/theme-design-pro',
      theme: {
        'css-prefix': 'next-icestark-',
      },
    }),
    icestark({ type: 'framework' }),
    store(),
    request()
  ],
  webpack: (webpackConfig) => {
    return ['mp3', 'mp4', 'wav'].reduce((acc, cur) => {
      return modifyLoader(acc, {
        rule: `.${cur}`,
        loader: 'url-loader',
        options: (originOptions) => {
          return {
            name: '[name].[ext]', // 输出文件名保持原样
            outputPath: 'assets/audio/', // 输出目录,可选
            publicPath: 'assets/audio/' // 公共路径,如果需要的话
          }
        },
      });
    }, webpackConfig);
  },
}));

Additional context

No response

ClarkXia commented 1 month ago

mp3 目前没有在框架的内置处理逻辑中,直接通过 addLoader 添加一条新的 webpack 处理规则就可以了

LOL871230823 commented 1 month ago

image 使用file-loader添加的规则不生效呢

LOL871230823 commented 1 month ago

image 还是同样的问题 @ClarkXia

LOL871230823 commented 1 month ago

@ClarkXia 大佬,能尽快回复一下吗?这个规则应该是怎么的?按照你们文档中提供的,好像不生效呢

ClarkXia commented 1 month ago

直接操作 webpack 配置,不要用 modifyRule 这个,类似 webpackConfig.module.rules.push(newRule)

LOL871230823 commented 1 month ago

image 完美解决,感谢