uni-app引入自定义图标后报错
按照uni-app官网https://uniapp.dcloud.io/component/uniui/uni-icons引入自定义图标后,报错信息如下:
18:23:01.393 Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
18:23:01.395 ModuleNotFoundError: Module not found: Error: Can't resolve './iconfont.ttf?t=1643100394872' in 'E:\project\patrol_system'
18:23:01.395 at D:\software\executepackage\HBuilderX.3.2.9.20210927\HBuilderX\plugins\uniapp-cli\node_modules\webpack\lib\Compilation.js:925:10
18:23:01.397 at D:\software\executepackage\HBuilderX.3.2.9.20210927\HBuilderX\plugins\uniapp-cli\node_modules\webpack\lib\NormalModuleFactory.js:401:22
18:23:01.397 at D:\software\executepackage\HBuilderX.3.2.9.20210927\HBuilderX\plugins\uniapp-cli\node_modules\webpack\lib\NormalModuleFactory.js:130:21
18:23:01.399 at D:\software\executepackage\HBuilderX.3.2.9.20210927\HBuilderX\plugins\uniapp-cli\node_modules\webpack\lib\NormalModuleFactory.js:224:22
18:23:01.399 at D:\software\executepackage\HBuilderX.3.2.9.20210927\HBuilderX\plugins\uniapp-cli\node_modules\neo-async\async.js:2830:7
18:23:01.400 at D:\software\executepackage\HBuilderX.3.2.9.20210927\HBuilderX\plugins\uniapp-cli\node_modules\neo-async\async.js:6877:13
18:23:01.400 at D:\software\executepackage\HBuilderX.3.2.9.20210927\HBuilderX\plugins\uniapp-cli\node_modules\webpack\lib\NormalModuleFactory.js:214:25
18:23:01.400 at D:\software\executepackage\HBuilderX.3.2.9.20210927\HBuilderX\plugins\uniapp-cli\node_modules\enhanced-resolve\lib\Resolver.js:213:14
18:23:01.405 at D:\software\executepackage\HBuilderX.3.2.9.20210927\HBuilderX\plugins\uniapp-cli\node_modules\enhanced-resolve\lib\Resolver.js:285:5
18:23:01.405 at eval (eval at create (D:\software\executepackage\HBuilderX.3.2.9.20210927\HBuilderX\plugins\uniapp-cli\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:13:1)
18:23:01.407 at D:\software\executepackage\HBuilderX.3.2.9.20210927\HBuilderX\plugins\uniapp-cli\node_modules\enhanced-resolve\lib\UnsafeCachePlugin.js:44:7
18:23:01.407 at D:\software\executepackage\HBuilderX.3.2.9.20210927\HBuilderX\plugins\uniapp-cli\node_modules\enhanced-resolve\lib\Resolver.js:285:5
18:23:01.407 at eval (eval at create (D:\software\executepackage\HBuilderX.3.2.9.20210927\HBuilderX\plugins\uniapp-cli\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:13:1)
18:23:01.407 at D:\software\executepackage\HBuilderX.3.2.9.20210927\HBuilderX\plugins\uniapp-cli\node_modules\enhanced-resolve\lib\Resolver.js:285:5
18:23:01.407 at eval (eval at create (D:\software\executepackage\HBuilderX.3.2.9.20210927\HBuilderX\plugins\uniapp-cli\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:25:1)
18:23:01.415 at D:\software\executepackage\HBuilderX.3.2.9.20210927\HBuilderX\plugins\uniapp-cli\node_modules\enhanced-resolve\lib\DescriptionFilePlugin.js:67:43
解决:
修改iconfont.css中src的引用路径如下(改成了绝对路径):
@font-face {
font-family: "iconfont";
src: url('~@/static/iconfont.ttf?t=1643100394872') format('truetype');
}