Skip to content

Instantly share code, notes, and snippets.

@mrukas
Created April 2, 2019 07:12
Show Gist options
  • Save mrukas/04df84826906772f799ffc4bb44fec02 to your computer and use it in GitHub Desktop.
Save mrukas/04df84826906772f799ffc4bb44fec02 to your computer and use it in GitHub Desktop.
SPFX compile specific webparts
'use strict';
const gulp = require('gulp');
const build = require('@microsoft/sp-build-web');
const coreBuild = require('@microsoft/sp-build-core-tasks');
const OptimizedWebpackTask = require('./OptimizedWebpackTask');
build.addSuppression(`Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.`);
build.tslint.enabled = false;
coreBuild.configureWebpack = new OptimizedWebpackTask();
build.initialize(gulp);
const ConfigureWebpackTask = require('@microsoft/sp-build-core-tasks/lib/configureWebpack/ConfigureWebpackTask').ConfigureWebpackTask;
class OptimizedWebpackTask extends ConfigureWebpackTask {
constructor() {
super(...arguments);
}
executeTask(gulp, completeCallback) {
const script = this.buildConfig.args._[0];
const webpart = this.buildConfig.args.webpart;
if (script === 'serve' && webpart) {
let bundleToCompile = this.properties.bundles[webpart];
if (!bundleToCompile) {
throw new Error("Webpart could not be found");
}
if (Object.keys(this.properties.bundles).length !== 1) {
this.properties.bundles = {
[webpart]: bundleToCompile
};
}
}
return super.executeTask(gulp, completeCallback);
}
}
module.exports = OptimizedWebpackTask;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment