Created
April 2, 2019 07:12
-
-
Save mrukas/04df84826906772f799ffc4bb44fec02 to your computer and use it in GitHub Desktop.
SPFX compile specific webparts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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