webpack - 在 SharePoint 框架 WebPart 中引用图像
问题描述
我正在尝试创建一个包含图像的简单 SharePoint Online WebPart。问题是没有显示打包在 WebPart 中的图像。
我找到了这个解决方案: https ://mattjimison.com/2017/06/03/referencing-images-sharepoint-framework-webpart/
但问题是当我这样做时出现错误gulp serve
:
[10:19:10] Finished subtask 'post-copy' after 4.25 ms
[10:19:10] Starting subtask 'collectLocalizedResources'...
Request: '/node_modules/@microsoft/sp-page-context/dist/sp-page-context.js'
[10:19:10] Finished subtask 'collectLocalizedResources' after 26 ms
[10:19:10] Starting subtask 'configure-webpack'...
[10:19:11] Finished subtask 'configure-webpack' after 561 ms
[10:19:11] Starting subtask 'webpack'...
Request: '/node_modules/@microsoft/sp-component-base/dist/sp-component-base.js'
Request: '/node_modules/@microsoft/sp-extension-base/dist/sp-extension-base_en-us.js'
Request: '/node_modules/@microsoft/sp-application-base/dist/sp-application-base_en-us.js'
Request: '/node_modules/react/dist/react.js'
Request: '/node_modules/react-dom/dist/react-dom.js'
[10:19:11] Error - [webpack] 'dist':
./lib/webparts/socialLinks/SocialLinksWebPart.js
Module not found: Error: Can't resolve 'set-webpack-public-path' in 'c:\runemy\git\spfx-social-links\lib\webparts\socialLinks'
resolve 'set-webpack-public-path' in 'c:\runemy\git\spfx-social-links\lib\webparts\socialLinks'
Parsed request is a module
using description file: c:\runemy\git\spfx-social-links\package.json (relative path: ./lib/webparts/socialLinks)
after using description file: c:\runemy\git\spfx-social-links\package.json (relative path: ./lib/webparts/socialLinks)
resolve as module
c:\runemy\git\spfx-social-links\lib\webparts\socialLinks\node_modules doesn't exist or is not a directory
c:\runemy\git\spfx-social-links\lib\webparts\node_modules doesn't exist or is not a directory
c:\runemy\git\spfx-social-links\lib\node_modules doesn't exist or is not a directory
c:\runemy\git\node_modules doesn't exist or is not a directory
c:\runemy\node_modules doesn't exist or is not a directory
looking for modules in c:\runemy\git\spfx-social-links\node_modules
using description file: c:\runemy\git\spfx-social-links\package.json (relative path: ./node_modules)
好像它是一个缺失的模块?我怎样才能启动并运行它?
解决方案
结案
案例通过以下方式解决:
npm install @microsoft/loader-set-webpack-public-path
npm install @microsoft/set-webpack-public-path-plugin --save-dev
并替换require('set-webpack-public-path!')
为require("@microsoft/loader-set-webpack-public-path!");
-符文
推荐阅读
- tensorflow - 本地超参数调优——Tensorflow Google Cloud ML Engine
- spring-cloud-config - spring cloud 配置多个配置文件
- javascript - 在 Material-UI TextField 中,当输入模糊时,如何防止标签落在装饰物后面?
- c# - 如何在 ASP.NET Identity Core 用户和自定义外部表之间建立多对多关系?
- excel - 按范围排序
- reactjs - 使用 Material UI 对话框时“无法读取 null 的属性‘offsetWidth’”
- jquery - 检查响应式 div 的内容溢出
- python - 使用 apply 将 Series 存储到 pandas DataFrame 单元格中
- javascript - 记忆化的组件让他们的孩子重新渲染
- javascript - 如何执行我的超凡活动();'console.log' 中的原型函数与其他字符串?那可能吗?