2017-09-04 02:20:56 +00: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');
|
2019-01-22 01:54:45 +00:00
|
|
|
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
2019-03-09 02:10:23 +00:00
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
|
|
const browsers = require('../browsers');
|
2017-09-04 02:20:56 +00:00
|
|
|
|
|
|
|
const uiFolder = 'UI';
|
2019-03-09 02:10:23 +00:00
|
|
|
const frontendFolder = path.join(__dirname, '..');
|
|
|
|
const srcFolder = path.join(frontendFolder, 'src');
|
2017-09-04 02:20:56 +00:00
|
|
|
const isProduction = process.argv.indexOf('--production') > -1;
|
|
|
|
|
2019-03-09 02:10:23 +00:00
|
|
|
console.log('Source Folder:', srcFolder);
|
2017-09-04 02:20:56 +00:00
|
|
|
console.log('isProduction:', isProduction);
|
|
|
|
|
2017-10-02 03:05:28 +00:00
|
|
|
const cssVarsFiles = [
|
2017-09-04 02:20:56 +00:00
|
|
|
'../src/Styles/Variables/colors',
|
|
|
|
'../src/Styles/Variables/dimensions',
|
|
|
|
'../src/Styles/Variables/fonts',
|
2019-05-11 01:56:04 +00:00
|
|
|
'../src/Styles/Variables/animations',
|
|
|
|
'../src/Styles/Variables/zIndexes'
|
2017-09-04 02:20:56 +00:00
|
|
|
].map(require.resolve);
|
|
|
|
|
2018-08-08 00:57:15 +00:00
|
|
|
const plugins = [
|
2019-01-22 01:54:45 +00:00
|
|
|
new OptimizeCssAssetsPlugin({}),
|
|
|
|
|
2018-08-08 00:57:15 +00:00
|
|
|
new webpack.DefinePlugin({
|
|
|
|
__DEV__: !isProduction,
|
|
|
|
'process.env.NODE_ENV': isProduction ? JSON.stringify('production') : JSON.stringify('development')
|
2019-03-09 02:10:23 +00:00
|
|
|
}),
|
|
|
|
|
|
|
|
new MiniCssExtractPlugin({
|
|
|
|
filename: path.join('_output', uiFolder, 'Content', 'styles.css')
|
2018-08-08 00:57:15 +00:00
|
|
|
})
|
|
|
|
];
|
|
|
|
|
2017-09-04 02:20:56 +00:00
|
|
|
const config = {
|
2019-03-09 02:10:23 +00:00
|
|
|
mode: isProduction ? 'production' : 'development',
|
2017-09-04 02:20:56 +00:00
|
|
|
devtool: '#source-map',
|
2018-08-08 00:57:15 +00:00
|
|
|
|
2017-09-04 02:20:56 +00:00
|
|
|
stats: {
|
|
|
|
children: false
|
|
|
|
},
|
2018-08-08 00:57:15 +00:00
|
|
|
|
2017-09-04 02:20:56 +00:00
|
|
|
watchOptions: {
|
|
|
|
ignored: /node_modules/
|
|
|
|
},
|
2018-08-08 00:57:15 +00:00
|
|
|
|
2017-09-04 02:20:56 +00:00
|
|
|
entry: {
|
|
|
|
preload: 'preload.js',
|
|
|
|
vendor: 'vendor.js',
|
|
|
|
index: 'index.js'
|
|
|
|
},
|
2018-08-08 00:57:15 +00:00
|
|
|
|
2017-09-04 02:20:56 +00:00
|
|
|
resolve: {
|
2017-10-02 03:05:28 +00:00
|
|
|
modules: [
|
2019-03-09 02:10:23 +00:00
|
|
|
srcFolder,
|
|
|
|
path.join(srcFolder, 'Shims'),
|
2017-10-02 03:05:28 +00:00
|
|
|
'node_modules'
|
2017-09-21 02:05:00 +00:00
|
|
|
],
|
|
|
|
alias: {
|
|
|
|
jquery: 'jquery/src/jquery'
|
|
|
|
}
|
2017-09-04 02:20:56 +00:00
|
|
|
},
|
2018-08-08 00:57:15 +00:00
|
|
|
|
2017-09-04 02:20:56 +00:00
|
|
|
output: {
|
|
|
|
filename: path.join('_output', uiFolder, '[name].js'),
|
|
|
|
sourceMapFilename: '[file].map'
|
|
|
|
},
|
2018-08-08 00:57:15 +00:00
|
|
|
|
2019-03-09 02:10:23 +00:00
|
|
|
optimization: {
|
|
|
|
chunkIds: 'named'
|
|
|
|
},
|
|
|
|
|
2018-08-08 00:57:15 +00:00
|
|
|
plugins,
|
|
|
|
|
2017-09-04 02:20:56 +00:00
|
|
|
resolveLoader: {
|
2017-10-02 03:05:28 +00:00
|
|
|
modules: [
|
2017-09-04 02:20:56 +00:00
|
|
|
'node_modules',
|
2017-10-02 03:05:28 +00:00
|
|
|
'frontend/gulp/webpack/'
|
2017-09-04 02:20:56 +00:00
|
|
|
]
|
|
|
|
},
|
2018-08-08 00:57:15 +00:00
|
|
|
|
2017-09-04 02:20:56 +00:00
|
|
|
module: {
|
2017-10-02 03:05:28 +00:00
|
|
|
rules: [
|
2017-09-04 02:20:56 +00:00
|
|
|
{
|
|
|
|
test: /\.js?$/,
|
|
|
|
exclude: /(node_modules|JsLibraries)/,
|
2019-03-09 02:10:23 +00: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',
|
|
|
|
targets: browsers
|
|
|
|
}
|
|
|
|
]
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2017-09-04 02:20:56 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// CSS Modules
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
exclude: /(node_modules|globals.css)/,
|
2019-03-09 02:10:23 +00:00
|
|
|
use: [
|
|
|
|
{ loader: MiniCssExtractPlugin.loader },
|
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
importLoaders: 1,
|
|
|
|
localIdentName: '[name]/[local]/[hash:base64:5]',
|
|
|
|
modules: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
options: {
|
|
|
|
ident: 'postcss',
|
|
|
|
config: {
|
|
|
|
ctx: {
|
|
|
|
cssVarsFiles
|
|
|
|
},
|
|
|
|
path: 'frontend/postcss.config.js'
|
2017-10-02 03:05:28 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-09 02:10:23 +00:00
|
|
|
}
|
|
|
|
]
|
2017-09-04 02:20:56 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Global styles
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
include: /(node_modules|globals.css)/,
|
2017-10-02 03:05:28 +00:00
|
|
|
use: [
|
|
|
|
'style-loader',
|
|
|
|
{
|
|
|
|
loader: 'css-loader'
|
|
|
|
}
|
|
|
|
]
|
2017-09-04 02:20:56 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Fonts
|
|
|
|
{
|
|
|
|
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
|
2017-10-02 03:05:28 +00:00
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'url-loader',
|
|
|
|
options: {
|
|
|
|
limit: 10240,
|
|
|
|
mimetype: 'application/font-woff',
|
|
|
|
emitFile: false,
|
|
|
|
name: 'Content/Fonts/[name].[ext]'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2017-09-04 02:20:56 +00:00
|
|
|
},
|
2017-10-02 03:05:28 +00:00
|
|
|
|
2017-09-04 02:20:56 +00:00
|
|
|
{
|
|
|
|
test: /\.(ttf|eot|eot?#iefix|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
|
2017-10-02 03:05:28 +00:00
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
|
|
|
emitFile: false,
|
|
|
|
name: 'Content/Fonts/[name].[ext]'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2017-09-04 02:20:56 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
gulp.task('webpack', () => {
|
2019-03-09 02:10:23 +00:00
|
|
|
return webpackStream(config, webpack)
|
|
|
|
.pipe(gulp.dest('./'));
|
2017-09-04 02:20:56 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('webpackWatch', () => {
|
|
|
|
config.watch = true;
|
2019-03-09 02:10:23 +00:00
|
|
|
|
|
|
|
return webpackStream(config, webpack)
|
2017-09-04 02:20:56 +00:00
|
|
|
.on('error', errorHandler)
|
2019-03-09 02:10:23 +00:00
|
|
|
.pipe(gulp.dest('./'))
|
2017-09-04 02:20:56 +00:00
|
|
|
.on('error', errorHandler)
|
|
|
|
.pipe(livereload())
|
|
|
|
.on('error', errorHandler);
|
|
|
|
});
|