-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgulpfile.js
89 lines (80 loc) · 3.56 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
'use strict';
const os = require('os');
const gulp = require('gulp');
const build = require('@microsoft/sp-build-web');
const path = require('path');
const log = require('@microsoft/gulp-core-build').log;
const colors = require("colors");
const bundleAnalyzer = require('webpack-bundle-analyzer');
const fs = require("fs");
/**
* Task is necessary for VSTS
*/
build.addSuppression(/^Warning - \[sass\].*$/);
const envCheck = build.subTask('environmentCheck', (gulp, config, done) => {
/********************************************************************************************
* Adds an alias for handlebars in order to avoid errors while gulping the project
* https://github.com/wycats/handlebars.js/issues/1174
* Adds a loader and a node setting for webpacking the handlebars-helpers correctly
* https://github.com/helpers/handlebars-helpers/issues/263
********************************************************************************************/
build.configureWebpack.mergeConfig({
additionalConfiguration: (generatedConfiguration) => {
fs.writeFileSync("./temp/_webpack_config.json", JSON.stringify(generatedConfiguration, null, 2));
/*
generatedConfiguration.resolve.alias = {
handlebars: 'handlebars/dist/handlebars.min.js'
};*/
// Check if running in debug or ship
if (config.production) {
generatedConfiguration.module.rules.push({
test: /\.js$/,
loader: 'unlazy-loader'
});
} else {
generatedConfiguration.module.rules.push({
test: /\.js$/,
loader: 'unlazy-loader',
exclude: [path.resolve(__dirname, './lib/')]
});
}
generatedConfiguration.node = {
fs: 'empty',
readline: 'empty'
}
if (config.production) {
log(`[${colors.cyan('configure-webpack')}] Adding plugin ${colors.cyan('BundleAnalyzerPlugin')}...`);
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'
}));
}
// Optimize build times - https://www.eliostruyf.com/speed-sharepoint-framework-builds-wsl-2/
if (!config.production) {
for (const rule of generatedConfiguration.module.rules) {
// Add include rule for webpack's source map loader
if (rule.use && typeof rule.use === 'string' && rule.use.indexOf('source-map-loader') !== -1) {
rule.include = [
path.resolve(__dirname, 'lib')
]
}
// Disable minification for css-loader
if (rule.use && rule.use instanceof Array && rule.use.length == 2 && rule.use[1].loader && rule.use[1].loader.indexOf('css-loader') !== -1) {
log(`[${colors.cyan('configure-webpack')}] Setting ${colors.cyan('css-loader')} to disable minification`);
rule.use[1].options.minimize = false;
}
}
}
return generatedConfiguration;
}
});
done();
});
build.rig.addPreBuildTask(envCheck);
build.initialize(gulp);