npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sharepointplus-loader

v1.1.8

Published

Webpack plugin that permits to leverage tree-shaking for https://aymkdn.github.io/SharepointPlus/ (starting from SharepointPlus v6.0)

Downloads

13

Readme

sharepointplus-loader

Webpack plugin that permits to leverage tree-shaking for https://aymkdn.github.io/SharepointPlus/ (starting from SharepointPlus v6.0)

Installation

npm install sharepointplus-loader

And, for regular Webpack config file (e.g. webpack.conf.js), add it to the plugins:

// ----- file 'webpack.conf.js'
const webpack = require('webpack');
const SharepointPlusLoaderPlugin = require('sharepointplus-loader/plugin'); // load the plugin
module.exports = {
  [ ... your configuration ...],
  plugins:[
    new SharepointPlusLoaderPlugin() // add the plugin here
  ]
};

Or if you work with SPFx you have to edit your gulpfile.js file:

// ----- file 'gulpfile.js'
const gulp = require('gulp');
const build = require('@microsoft/sp-build-web');
[ ... your configuration ... ]

// add the plugin with the below block of code:
const webpack = require('webpack');
const SharepointPlusLoaderPlugin = require('sharepointplus-loader/plugin'); // load the plugin
build.configureWebpack.mergeConfig({
  additionalConfiguration: (generatedConfig) => {
    if (!Array.isArray(generatedConfig.plugins)) generatedConfig.plugins=[];
    generatedConfig.plugins.push(new SharepointPlusLoaderPlugin()); // add the plugin here
    // return modified config => SPFx build pipeline
    return generatedConfig;
  }
});

build.initialize(gulp);

How it works

The plugin will analyze your code, in files with extension .js, .jsx, .ts and .vue, to detect the below line:

import $SP from 'sharepointplus'

Then it will replace it with a similar code as the one below:

import spInit from 'sharepointplus/es5/init.js'
import list from 'sharepointplus/es5/lists/list.js' // if `$SP().list()` is used in the analyzed file
import get from 'sharepointplus/es5/lists/get.js' // if `$SP().list().get()` is used in the analyzed file
import getPeopleLookup from 'sharepointplus/es5/utils/getPeopleLookup.js'  // if `$SP().getPeopleLookup()` is used in the analyzed file
const $SP = spInit({'list':list, 'get':get, 'getPeopleLookup':getPeopleLookup });

Complex project

If your project has several files using SharepointPlus, but you only want to load it as a global object with only what matters, then you can use // sp-loader-path: "./path/" in your main file.

Example with the below hierarchy:

.
+-- classes/
| |-- Files.js
| +-- Folders.js
+-- components/
| |-- App.vue
| |-- Header.vue
| +-- Footer.vue
+-- plugins/
| +-- vuetify.js
+-- store/
| |-- files.js
| |-- folders.js
| +-- list.js
+-- index.js

We have several calls of $SP() all other the place, but we want all of them to be loaded by index.js. We will only call import $SP from 'sharepointplus' in index.js and we'll use sp-loader-path as the below:

// index.js – before sharepoint-loader has analyzed it

// Load $SP modules from files in the below path,
//   using glob patterns (see https://github.com/isaacs/node-glob#readme)
// sp-loader-path: "./classes/**"
// sp-loader-path: "./components/**"
// sp-loader-path: "./store/**"
import $SP from 'sharepointplus'
global.$SP = $SP; // to make sure it will be available everywhere

Once sharepointplus-loader has analyzed the file, it will convert it to load all the necessary modules:

// index.js – after sharepoint-loader has analyzed it

// all the modules from the sub files have been listed and are loaded
import spInit from 'sharepointplus/es5/init.js'
import cleanResult from 'sharepointplus/es5/lists/cleanResult.js'
import getLookup from 'sharepointplus/es5/utils/getLookup.js'
import getPeopleLookup from 'sharepointplus/es5/utils/getPeopleLookup.js'
import toDate from 'sharepointplus/es5/utils/toDate.js'
import showModalDialog from 'sharepointplus/es5/modals/showModalDialog.js'
import closeModalDialog from 'sharepointplus/es5/modals/closeModalDialog.js'
import ajax from 'sharepointplus/es5/utils/ajax.js'
import list from 'sharepointplus/es5/lists/list.js'
import add from 'sharepointplus/es5/lists/add.js'
import get from 'sharepointplus/es5/lists/get.js'
import workflowStatusToText from 'sharepointplus/es5/utils/workflowStatusToText.js'
import getWorkflowID from 'sharepointplus/es5/lists/getWorkflowID.js'
import startWorkflow from 'sharepointplus/es5/lists/startWorkflow.js'
import remove from 'sharepointplus/es5/lists/remove.js'
import update from 'sharepointplus/es5/lists/update.js'
import getContentTypeInfo from 'sharepointplus/es5/lists/getContentTypeInfo.js'
import toSPDate from 'sharepointplus/es5/utils/toSPDate.js'
import webService from 'sharepointplus/es5/utils/webService.js'
import createFile from 'sharepointplus/es5/files/createFile.js'
const $SP = spInit({cleanResult:cleanResult, getLookup:getLookup, getPeopleLookup:getPeopleLookup, toDate:toDate, showModalDialog:showModalDialog, closeModalDialog:closeModalDialog, ajax:ajax, list:list, add:add, get:get, workflowStatusToText:workflowStatusToText, getWorkflowID:getWorkflowID, startWorkflow:startWorkflow, remove:remove, update:update, getContentTypeInfo:getContentTypeInfo, toSPDate:toSPDate, webService:webService, createFile:createFile});
global.$SP = $SP; // to make sure it will be available everywhere