2

Does anyone know if we could provision js files to SharePoint site using SharePoint Framework ?

I read on Microsoft Dev that it could provision SharePoint data (sitecolumns, contenttypes, lists) but nothing about the document files (js, css is my concern for now).

Thanks,

  • Yes of course :) youtube.com/watch?v=W_ABwoHrEls&t=594s – Goshky Sep 26 '17 at 11:55
  • @Goshky I couldn't find any thing like that in the vids. All they said are about provision lists, etc...And they are using SPFx v1.3 – Thi Vo Sep 27 '17 at 3:08
  • Why would you want to provision separate .js and .css files rather than including them in the generated bundle? – Waldek Mastykarz - MVP Sep 28 '17 at 16:56
  • @WaldekMastykarz-MVP: My solution needs to work on both Classic and Modern UI. So I was trying to inject the js and css into Custom Actions in Classic UI. And I need to know the link to send to the ScriptLink. Hence the link need to be static. – Thi Vo Oct 4 '17 at 2:40
  • @Thi: Classic and modern UI are based on two different sets of APIs so not sure you will be able to reuse as much of your code base as you'd need to make this approach worth the effort. – Waldek Mastykarz - MVP Oct 4 '17 at 6:08
4

I found the answer. I have to include it in the elements.xml as normally.

<Module Name="Files" Url="SiteAssets">
    <File Path="test.js" Url="test.js" Type="GhostableInLibrary" ReplaceContent="TRUE" >
    </File>
</Module>

Then reference the file in package-solution.json:

"assets": {        
    "elementManifests": [
      "elements.xml"
    ],
    "elementFiles":[
      "test.js"
    ]
  }

Finally, I have to extract the package using WinRar or something and include the js extension in the [Content_Types].xml (If the extension has already been here then you dont have to do this step. Right now it has .jpg, .pnp, .gif, .xml, .rels, .webpart, .htm, .aspx, .resx)

<Default Extension="js" ContentType="application/wsp"></Default>

Trying to figure how to include js extension by default using gulp package-solution. Really hope MS will do this later instead of leaving out the .js (and .css) files

  • Just stumbled across the issue that you have to unpack the solution and add the content type. Do you have any idea how to do that during the packaging/bundling process? – Andreas Oct 22 '18 at 14:05
  • Sorry I only know how to do that manually, if you want to do that during bundle you have to research on gulp. – Thi Vo Oct 23 '18 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.