microsoft-graph-toolkit icon indicating copy to clipboard operation
microsoft-graph-toolkit copied to clipboard

[QUESTION] When using MGT with SPFx 1.19, are the changes in the gulpfile.js still necesary?

Open Rafaelki opened this issue 1 year ago • 3 comments

Support Question

Hi, My understanding is that the changes in the gulpfile.js are needed because SPFx was using an old version of Webpack. As SPFx 1.19 uses webpack 5, are these changes still needed?

If they are not needed or using webpack 5 has any impact on them, could you please update your sample in https://github.com/pnp/mgt-samples/tree/main/samples/app/sp-webpart to SPFx 1.19.

Related to: #3045

Thanks!

Rafaelki avatar Jul 19 '24 12:07 Rafaelki

Pinging @gavinbarron to shed some light on this :)

musale avatar Jul 31 '24 15:07 musale

I'm running into the same issue

JonoSuave avatar Jul 31 '24 20:07 JonoSuave

@musale here's what my updated gulpfile looks like that seems to work:

"use strict";

const build = require("@microsoft/sp-build-web");
const path = require("path");

build.addSuppression(
	`Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.`
);

var getTasks = build.rig.getTasks;
build.rig.getTasks = function () {
	var result = getTasks.call(build.rig);

	result.set("serve", result.get("serve-deprecated"));

	return result;
};

// add babel-loader and some transforms to handle es2021 language features which are unsupported in webpack 4 by default
const litFolders = [
	`node_modules${path.sep}lit${path.sep}`,
	`node_modules${path.sep}@lit${path.sep}`,
	`node_modules${path.sep}lit-html${path.sep}`,
	`node_modules${path.sep}lit-element${path.sep}`,
];
build.configureWebpack.mergeConfig({
	additionalConfiguration: (generatedConfiguration) => {
		generatedConfiguration.module.rules.push({
			test: /\.js$/,
			// only run on lit packages in the root node_module folder
			include: (resourcePath) => litFolders.some((litFolder) => resourcePath.includes(litFolder)),
			use: {
				loader: "babel-loader",
				options: {
					plugins: [
						"@babel/plugin-transform-optional-chaining",
						"@babel/plugin-transform-nullish-coalescing-operator",
						"@babel/plugin-transform-logical-assignment-operators",
					],
				},
			},
		});
		return generatedConfiguration;
	},
});

build.initialize(require("gulp"));

JonoSuave avatar Aug 01 '24 15:08 JonoSuave

We are getting the issue with MGT + SPFx 1.19 even after including lit-element in the gulp file.

@gavinbarron @musale

akshataggrwal avatar Oct 16 '24 07:10 akshataggrwal

@akshataggrwal what's the output of the issue you're getting? I'm able to build with mgt and spfx 1.19. Please open an issue on pnp repo with all details, thanks.

musale avatar Oct 17 '24 11:10 musale

@Rafaelki no.

I have created these issues on pnp side to address this:

  • https://github.com/pnp/mgt-samples/issues/24
  • https://github.com/pnp/mgt-samples/issues/23

Closing this question.

musale avatar Oct 17 '24 11:10 musale