UNPKG

@pnp/generator-spfx

Version:

This Yeoman generator helps organisations to improve their development workflow with the SharePoint Framework. It extends the functionalities of the @microsoft/generator-sharepoint based on best pattern and practices. This generator extends the capabiliti

108 lines (84 loc) 2.83 kB
<% var webpackBundleAnalyzer = false; var stylelint = false; var ci = false; if (undefined !== SpfxOptions) { // Check for webpack bundle analyzer if(SpfxOptions['pnp-vetting'].indexOf('webpack-analyzer') !== -1){ webpackBundleAnalyzer = true; } if(SpfxOptions['pnp-vetting'].indexOf('stylelint') !== -1){ stylelint = true; } if(SpfxOptions['pnp-ci'].length !== 0){ ci = true; } } %>'use strict'; // check if gulp dist was called if (process.argv.indexOf('dist') !== -1) { // add ship options to command call process.argv.push('--ship'); } const path = require('path'); const gulp = require('gulp'); const build = require('@microsoft/sp-build-web'); const gulpSequence = require('gulp-sequence'); build.addSuppression(`Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.`); // Create clean distrubution package gulp.task('dist', gulpSequence('clean', 'bundle', 'package-solution')); // Create clean development package gulp.task('dev', gulpSequence('clean', 'bundle', 'package-solution')); <% if(webpackBundleAnalyzer) {%> /** * Webpack Bundle Anlayzer * Reference and gulp task */ if (process.argv.indexOf('--analyze') !== -1 || process.argv.indexOf('dist') !== -1 || process.argv.indexOf('dev') !== -1) { const bundleAnalyzer = require('webpack-bundle-analyzer'); build.configureWebpack.mergeConfig({ additionalConfiguration: (generatedConfiguration) => { const lastDirName = path.basename(__dirname); const dropPath = path.join(__dirname, 'temp', 'stats'); generatedConfiguration.plugins.push(new bundleAnalyzer.BundleAnalyzerPlugin({ openAnalyzer: false, analyzerMode: 'static', reportFilename: path.join(dropPath, `${lastDirName}.stats.html`), generateStatsFile: true, statsFilename: path.join(dropPath, `${lastDirName}.stats.json`), logLevel: 'error' })); return generatedConfiguration; } }); } <% }; %> <% if(stylelint) {%> /** * StyleLinter configuration * Reference and custom gulp task */ const stylelint = require('gulp-stylelint'); /* Stylelinter sub task */ let styleLintSubTask = build.subTask('stylelint', (gulp) => { console.log('[stylelint]: By default style lint errors will not break your build. If you want to change this behaviour, modify failAfterError parameter in gulpfile.js.'); return gulp .src('src/**/*.scss') .pipe(stylelint({ failAfterError: false, reporters: [{ formatter: 'string', console: true }] })); }); /* end sub task */ build.rig.addPreBuildTask(styleLintSubTask); <% }; %> /** * Custom Framework Specific gulp tasks */ <%- customTasks %> build.initialize(gulp);