2018-11-23 08:04:42 +01:00
|
|
|
const gulp = require('gulp');
|
|
|
|
const webpackStream = require('webpack-stream');
|
|
|
|
const livereload = require('gulp-livereload');
|
|
|
|
const path = require('path');
|
|
|
|
const webpack = require('webpack');
|
|
|
|
const errorHandler = require('./helpers/errorHandler');
|
2020-06-28 00:13:31 +02:00
|
|
|
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
2019-04-13 05:25:58 +02:00
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
2019-11-27 15:19:35 +01:00
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
|
|
const TerserPlugin = require('terser-webpack-plugin');
|
2018-11-23 08:04:42 +01:00
|
|
|
|
|
|
|
const uiFolder = 'UI';
|
2019-04-13 05:25:58 +02:00
|
|
|
const frontendFolder = path.join(__dirname, '..');
|
|
|
|
const srcFolder = path.join(frontendFolder, 'src');
|
2018-11-23 08:04:42 +01:00
|
|
|
const isProduction = process.argv.indexOf('--production') > -1;
|
2019-11-27 15:19:35 +01:00
|
|
|
const isProfiling = isProduction && process.argv.indexOf('--profile') > -1;
|
2020-06-06 23:03:15 +02:00
|
|
|
const inlineWebWorkers = true;
|
2019-11-27 15:19:35 +01:00
|
|
|
|
|
|
|
const distFolder = path.resolve(frontendFolder, '..', '_output', uiFolder);
|
2018-11-23 08:04:42 +01:00
|
|
|
|
2019-04-13 05:25:58 +02:00
|
|
|
console.log('Source Folder:', srcFolder);
|
2019-11-27 15:19:35 +01:00
|
|
|
console.log('Output Folder:', distFolder);
|
2018-11-23 08:04:42 +01:00
|
|
|
console.log('isProduction:', isProduction);
|
2020-03-21 03:20:47 +01:00
|
|
|
console.log('isProfiling:', isProfiling);
|
2018-11-23 08:04:42 +01:00
|
|
|
|
|
|
|
const cssVarsFiles = [
|
|
|
|
'../src/Styles/Variables/colors',
|
|
|
|
'../src/Styles/Variables/dimensions',
|
|
|
|
'../src/Styles/Variables/fonts',
|
2019-06-14 05:54:25 +02:00
|
|
|
'../src/Styles/Variables/animations',
|
|
|
|
'../src/Styles/Variables/zIndexes'
|
2018-11-23 08:04:42 +01:00
|
|
|
].map(require.resolve);
|
|
|
|
|
2019-11-27 15:19:35 +01:00
|
|
|
// Override the way HtmlWebpackPlugin injects the scripts
|
|
|
|
HtmlWebpackPlugin.prototype.injectAssetsIntoHtml = function(html, assets, assetTags) {
|
|
|
|
const head = assetTags.head.map((v) => {
|
|
|
|
v.attributes = { rel: 'stylesheet', type: 'text/css', href: `/${v.attributes.href.replace('\\', '/')}` };
|
|
|
|
return this.createHtmlTag(v);
|
|
|
|
});
|
|
|
|
const body = assetTags.body.map((v) => {
|
|
|
|
v.attributes = { src: `/${v.attributes.src}` };
|
|
|
|
return this.createHtmlTag(v);
|
|
|
|
});
|
|
|
|
|
|
|
|
return html
|
|
|
|
.replace('<!-- webpack bundles head -->', head.join('\r\n '))
|
|
|
|
.replace('<!-- webpack bundles body -->', body.join('\r\n '));
|
|
|
|
};
|
|
|
|
|
2018-11-23 08:04:42 +01:00
|
|
|
const plugins = [
|
2020-06-28 00:13:31 +02:00
|
|
|
new OptimizeCssAssetsPlugin({}),
|
|
|
|
|
2018-11-23 08:04:42 +01:00
|
|
|
new webpack.DefinePlugin({
|
|
|
|
__DEV__: !isProduction,
|
|
|
|
'process.env.NODE_ENV': isProduction ? JSON.stringify('production') : JSON.stringify('development')
|
2019-04-13 05:25:58 +02:00
|
|
|
}),
|
|
|
|
|
|
|
|
new MiniCssExtractPlugin({
|
2019-11-27 15:19:35 +01:00
|
|
|
filename: path.join('Content', 'styles.css')
|
|
|
|
}),
|
|
|
|
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: 'frontend/src/index.html',
|
|
|
|
filename: 'index.html'
|
2018-11-23 08:04:42 +01:00
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
const config = {
|
2019-04-13 05:25:58 +02:00
|
|
|
mode: isProduction ? 'production' : 'development',
|
2018-11-23 08:04:42 +01:00
|
|
|
devtool: '#source-map',
|
|
|
|
|
|
|
|
stats: {
|
|
|
|
children: false
|
|
|
|
},
|
|
|
|
|
|
|
|
watchOptions: {
|
|
|
|
ignored: /node_modules/
|
|
|
|
},
|
|
|
|
|
|
|
|
entry: {
|
|
|
|
index: 'index.js'
|
|
|
|
},
|
|
|
|
|
|
|
|
resolve: {
|
|
|
|
modules: [
|
2019-04-13 05:25:58 +02:00
|
|
|
srcFolder,
|
|
|
|
path.join(srcFolder, 'Shims'),
|
2018-11-23 08:04:42 +01:00
|
|
|
'node_modules'
|
|
|
|
],
|
|
|
|
alias: {
|
|
|
|
jquery: 'jquery/src/jquery'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
output: {
|
2019-11-27 15:19:35 +01:00
|
|
|
path: distFolder,
|
|
|
|
filename: '[name].js',
|
2018-11-23 08:04:42 +01:00
|
|
|
sourceMapFilename: '[file].map'
|
|
|
|
},
|
|
|
|
|
2019-04-13 05:25:58 +02:00
|
|
|
optimization: {
|
2019-11-27 15:19:35 +01:00
|
|
|
chunkIds: 'named',
|
|
|
|
splitChunks: {
|
|
|
|
chunks: 'initial'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
performance: {
|
|
|
|
hints: false
|
2019-04-13 05:25:58 +02:00
|
|
|
},
|
|
|
|
|
2018-11-23 08:04:42 +01:00
|
|
|
plugins,
|
|
|
|
|
|
|
|
resolveLoader: {
|
|
|
|
modules: [
|
|
|
|
'node_modules',
|
|
|
|
'frontend/gulp/webpack/'
|
|
|
|
]
|
|
|
|
},
|
|
|
|
|
|
|
|
module: {
|
|
|
|
rules: [
|
2019-11-27 15:19:35 +01:00
|
|
|
{
|
|
|
|
test: /\.worker\.js$/,
|
|
|
|
use: {
|
|
|
|
loader: 'worker-loader',
|
|
|
|
options: {
|
2020-06-06 23:03:15 +02:00
|
|
|
name: '[name].js',
|
|
|
|
inline: inlineWebWorkers,
|
|
|
|
fallback: !inlineWebWorkers
|
2019-11-27 15:19:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2018-11-23 08:04:42 +01:00
|
|
|
{
|
|
|
|
test: /\.js?$/,
|
|
|
|
exclude: /(node_modules|JsLibraries)/,
|
2019-04-13 05:25:58 +02:00
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
configFile: `${frontendFolder}/babel.config.js`,
|
|
|
|
envName: isProduction ? 'production' : 'development',
|
|
|
|
presets: [
|
|
|
|
[
|
|
|
|
'@babel/preset-env',
|
|
|
|
{
|
|
|
|
modules: false,
|
|
|
|
loose: true,
|
|
|
|
debug: false,
|
|
|
|
useBuiltIns: 'entry',
|
2019-07-27 07:33:33 +02:00
|
|
|
corejs: 3
|
2019-04-13 05:25:58 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
]
|
2018-11-23 08:04:42 +01:00
|
|
|
}
|
|
|
|
}
|
2019-04-13 05:25:58 +02:00
|
|
|
]
|
2018-11-23 08:04:42 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
// CSS Modules
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
exclude: /(node_modules|globals.css)/,
|
2019-04-13 05:25:58 +02:00
|
|
|
use: [
|
|
|
|
{ loader: MiniCssExtractPlugin.loader },
|
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
importLoaders: 1,
|
2019-07-27 07:33:33 +02:00
|
|
|
modules: {
|
|
|
|
localIdentName: '[name]/[local]/[hash:base64:5]'
|
|
|
|
}
|
2019-04-13 05:25:58 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
options: {
|
|
|
|
ident: 'postcss',
|
|
|
|
config: {
|
|
|
|
ctx: {
|
|
|
|
cssVarsFiles
|
|
|
|
},
|
|
|
|
path: 'frontend/postcss.config.js'
|
2018-11-23 08:04:42 +01:00
|
|
|
}
|
|
|
|
}
|
2019-04-13 05:25:58 +02:00
|
|
|
}
|
|
|
|
]
|
2018-11-23 08:04:42 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
// Global styles
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
include: /(node_modules|globals.css)/,
|
|
|
|
use: [
|
|
|
|
'style-loader',
|
|
|
|
{
|
|
|
|
loader: 'css-loader'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
|
|
|
|
// Fonts
|
|
|
|
{
|
|
|
|
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'url-loader',
|
|
|
|
options: {
|
|
|
|
limit: 10240,
|
|
|
|
mimetype: 'application/font-woff',
|
|
|
|
emitFile: false,
|
|
|
|
name: 'Content/Fonts/[name].[ext]'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
test: /\.(ttf|eot|eot?#iefix|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
|
|
|
emitFile: false,
|
|
|
|
name: 'Content/Fonts/[name].[ext]'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-11-27 15:19:35 +01:00
|
|
|
if (isProfiling) {
|
|
|
|
config.resolve.alias['react-dom$'] = 'react-dom/profiling';
|
|
|
|
config.resolve.alias['scheduler/tracing'] = 'scheduler/tracing-profiling';
|
|
|
|
|
|
|
|
config.optimization.minimizer = [
|
|
|
|
new TerserPlugin({
|
|
|
|
cache: true,
|
|
|
|
parallel: true,
|
|
|
|
sourceMap: true, // Must be set to true if using source-maps in production
|
|
|
|
terserOptions: {
|
|
|
|
mangle: false,
|
|
|
|
keep_classnames: true,
|
|
|
|
keep_fnames: true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2018-11-23 08:04:42 +01:00
|
|
|
gulp.task('webpack', () => {
|
2019-04-13 05:25:58 +02:00
|
|
|
return webpackStream(config)
|
2019-11-27 15:19:35 +01:00
|
|
|
.pipe(gulp.dest('_output/UI'));
|
2018-11-23 08:04:42 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('webpackWatch', () => {
|
|
|
|
config.watch = true;
|
2019-04-13 05:25:58 +02:00
|
|
|
|
2020-06-28 00:13:31 +02:00
|
|
|
return webpackStream(config, webpack)
|
2018-11-23 08:04:42 +01:00
|
|
|
.on('error', errorHandler)
|
2019-11-27 15:19:35 +01:00
|
|
|
.pipe(gulp.dest('_output/UI'))
|
2018-11-23 08:04:42 +01:00
|
|
|
.on('error', errorHandler)
|
|
|
|
.pipe(livereload())
|
|
|
|
.on('error', errorHandler);
|
|
|
|
});
|