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

组件内引用静态资源,运行 npm run build 报错 #389

Closed
yuzhou1990 opened this issue Aug 11, 2021 · 1 comment
Closed

组件内引用静态资源,运行 npm run build 报错 #389

yuzhou1990 opened this issue Aug 11, 2021 · 1 comment

Comments

@yuzhou1990
Copy link

使用 npx @umijs/create-dumi-lib 生成项目,将打包模式改为 babel

配置 extraBabelPlugins

extraBabelPlugins:[
    [
      "file-loader",
      {
        "name": "[hash].[ext]",
        "extensions": ["png", "jpg", "jpeg", "gif", "svg"],
        "publicPath": "/public",
        "outputPath": "/public",
        "context": "",
        "limit": 0
      }
    ]
  ]

运行 npm run build 失败

> [email protected] build /Users/seventh/Documents/workspace/test-file
> father-build

Clean dist directory
Build cjs with babel
Clean lib directory
src/Foo/index.tsx(2,19): error TS2307: Cannot find module './empty.svg' or its corresponding type declarations.
Transform to cjs for src/index.js
Transform to cjs for src/Foo/index.js
TypeScript: 1 semantic error
TypeScript: emit succeeded (with errors)
events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: TypeScript: Compilation failed
    at Output.mightFinish (/Users/seventh/Documents/workspace/test-file/node_modules/gulp-typescript/release/output.js:130:43)
    at /Users/seventh/Documents/workspace/test-file/node_modules/gulp-typescript/release/output.js:43:22
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
Emitted 'error' event on Duplexify instance at:
    at Duplexify._destroy (/Users/seventh/Documents/workspace/test-file/node_modules/duplexify/index.js:191:15)
    at /Users/seventh/Documents/workspace/test-file/node_modules/duplexify/index.js:182:10
    at processTicksAndRejections (internal/process/task_queues.js:75:11)

复现地址:https://github.com/TwoOld/father-build-file

@yuzhou1990 yuzhou1990 changed the title 如何打包静态资源,例如 svg ? 组件内引用静态资源,运行 npm run build 报错 Aug 11, 2021
@yuzhou1990
Copy link
Author

解决方法:#227 (comment)

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

No branches or pull requests

1 participant