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

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

Closed
LOL871230823 opened this issue May 15, 2024 · 6 comments
Assignees
Labels

Comments

@LOL871230823
Copy link

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 ClarkXia self-assigned this May 15, 2024
@ClarkXia
Copy link
Collaborator

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

@LOL871230823
Copy link
Author

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

@LOL871230823
Copy link
Author

image
还是同样的问题 @ClarkXia

@LOL871230823
Copy link
Author

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

@ClarkXia
Copy link
Collaborator

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

@LOL871230823
Copy link
Author

image
完美解决,感谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants