2017-02-11 06:50:16 +00:00
|
|
|
const path = require('path');
|
|
|
|
const webpack = require('webpack');
|
2021-05-19 06:22:34 +00:00
|
|
|
const FileManagerPlugin = require('filemanager-webpack-plugin');
|
2019-08-19 18:37:27 +00:00
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
2021-04-24 18:48:57 +00:00
|
|
|
const LiveReloadPlugin = require('webpack-livereload-plugin');
|
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
2020-01-05 21:17:21 +00:00
|
|
|
const TerserPlugin = require('terser-webpack-plugin');
|
2017-02-11 06:50:16 +00:00
|
|
|
|
2021-04-25 01:06:22 +00:00
|
|
|
module.exports = (env) => {
|
|
|
|
const uiFolder = 'UI';
|
|
|
|
const frontendFolder = path.join(__dirname, '..');
|
|
|
|
const srcFolder = path.join(frontendFolder, 'src');
|
|
|
|
const isProduction = !!env.production;
|
|
|
|
const isProfiling = isProduction && !!env.profile;
|
|
|
|
const inlineWebWorkers = 'no-fallback';
|
2017-02-11 06:50:16 +00:00
|
|
|
|
2021-04-25 01:06:22 +00:00
|
|
|
const distFolder = path.resolve(frontendFolder, '..', '_output', uiFolder);
|
2019-08-19 18:37:27 +00:00
|
|
|
|
2021-04-25 01:06:22 +00:00
|
|
|
console.log('Source Folder:', srcFolder);
|
|
|
|
console.log('Output Folder:', distFolder);
|
|
|
|
console.log('isProduction:', isProduction);
|
|
|
|
console.log('isProfiling:', isProfiling);
|
2017-02-11 06:50:16 +00:00
|
|
|
|
2021-04-25 01:06:22 +00:00
|
|
|
const config = {
|
|
|
|
mode: isProduction ? 'production' : 'development',
|
2021-05-19 06:22:34 +00:00
|
|
|
devtool: isProduction ? 'source-map' : 'eval-source-map',
|
2018-01-13 02:01:27 +00:00
|
|
|
|
2021-04-25 01:06:22 +00:00
|
|
|
stats: {
|
|
|
|
children: false
|
|
|
|
},
|
2018-01-13 02:01:27 +00:00
|
|
|
|
2021-04-25 01:06:22 +00:00
|
|
|
watchOptions: {
|
|
|
|
ignored: /node_modules/
|
|
|
|
},
|
2018-01-13 02:01:27 +00:00
|
|
|
|
2021-04-25 01:06:22 +00:00
|
|
|
entry: {
|
|
|
|
index: 'index.js'
|
|
|
|
},
|
2018-01-13 02:01:27 +00:00
|
|
|
|
2021-04-25 01:06:22 +00:00
|
|
|
resolve: {
|
|
|
|
modules: [
|
|
|
|
srcFolder,
|
|
|
|
path.join(srcFolder, 'Shims'),
|
|
|
|
'node_modules'
|
|
|
|
],
|
|
|
|
alias: {
|
2021-12-05 18:07:43 +00:00
|
|
|
jquery: 'jquery/src/jquery',
|
|
|
|
'react-middle-truncate': 'react-middle-truncate/lib/react-middle-truncate'
|
2021-04-25 01:06:22 +00:00
|
|
|
}
|
|
|
|
},
|
2018-01-13 02:01:27 +00:00
|
|
|
|
2021-04-25 01:06:22 +00:00
|
|
|
output: {
|
|
|
|
path: distFolder,
|
|
|
|
publicPath: '/',
|
|
|
|
filename: '[name].js',
|
|
|
|
sourceMapFilename: '[file].map'
|
|
|
|
},
|
2018-01-13 02:01:27 +00:00
|
|
|
|
2021-04-25 01:06:22 +00:00
|
|
|
optimization: {
|
|
|
|
moduleIds: 'deterministic',
|
|
|
|
chunkIds: 'named',
|
|
|
|
splitChunks: {
|
|
|
|
chunks: 'initial',
|
|
|
|
name: 'vendors'
|
|
|
|
}
|
|
|
|
},
|
2019-08-19 18:37:27 +00:00
|
|
|
|
2021-04-25 01:06:22 +00:00
|
|
|
performance: {
|
|
|
|
hints: false
|
|
|
|
},
|
2019-03-03 19:29:12 +00:00
|
|
|
|
2021-04-25 01:06:22 +00:00
|
|
|
plugins: [
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
__DEV__: !isProduction,
|
|
|
|
'process.env.NODE_ENV': isProduction ? JSON.stringify('production') : JSON.stringify('development')
|
|
|
|
}),
|
2021-04-24 18:48:57 +00:00
|
|
|
|
2021-04-25 01:06:22 +00:00
|
|
|
new MiniCssExtractPlugin({
|
|
|
|
filename: 'Content/styles.css'
|
|
|
|
}),
|
2021-04-24 18:48:57 +00:00
|
|
|
|
2021-04-25 01:06:22 +00:00
|
|
|
new HtmlWebpackPlugin({
|
2021-05-19 06:22:34 +00:00
|
|
|
template: 'frontend/src/index.ejs',
|
2021-04-25 01:06:22 +00:00
|
|
|
filename: 'index.html',
|
|
|
|
publicPath: '/'
|
|
|
|
}),
|
2021-04-24 18:48:57 +00:00
|
|
|
|
2021-05-19 06:22:34 +00:00
|
|
|
new FileManagerPlugin({
|
|
|
|
events: {
|
|
|
|
onEnd: {
|
|
|
|
copy: [
|
|
|
|
// HTML
|
|
|
|
{
|
|
|
|
source: 'frontend/src/*.html',
|
|
|
|
destination: distFolder
|
|
|
|
},
|
|
|
|
|
|
|
|
// Fonts
|
|
|
|
{
|
|
|
|
source: 'frontend/src/Content/Fonts/*.*',
|
|
|
|
destination: path.join(distFolder, 'Content/Fonts')
|
|
|
|
},
|
|
|
|
|
|
|
|
// Icon Images
|
|
|
|
{
|
|
|
|
source: 'frontend/src/Content/Images/Icons/*.*',
|
|
|
|
destination: path.join(distFolder, 'Content/Images/Icons')
|
|
|
|
},
|
|
|
|
|
|
|
|
// Images
|
|
|
|
{
|
|
|
|
source: 'frontend/src/Content/Images/*.*',
|
|
|
|
destination: path.join(distFolder, 'Content/Images')
|
|
|
|
},
|
|
|
|
|
|
|
|
// Robots
|
|
|
|
{
|
|
|
|
source: 'frontend/src/Content/robots.txt',
|
|
|
|
destination: path.join(distFolder, 'Content/robots.txt')
|
|
|
|
}
|
|
|
|
]
|
2021-04-25 01:06:22 +00:00
|
|
|
}
|
2021-05-19 06:22:34 +00:00
|
|
|
}
|
2021-04-25 01:06:22 +00:00
|
|
|
}),
|
2021-04-24 18:48:57 +00:00
|
|
|
|
2021-04-25 01:06:22 +00:00
|
|
|
new LiveReloadPlugin()
|
|
|
|
],
|
2018-01-13 02:01:27 +00:00
|
|
|
|
2021-04-25 01:06:22 +00:00
|
|
|
resolveLoader: {
|
|
|
|
modules: [
|
|
|
|
'node_modules',
|
|
|
|
'frontend/build/webpack/'
|
|
|
|
]
|
|
|
|
},
|
2018-01-13 02:01:27 +00:00
|
|
|
|
2021-04-25 01:06:22 +00:00
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.worker\.js$/,
|
|
|
|
use: {
|
|
|
|
loader: 'worker-loader',
|
2019-03-03 19:29:12 +00:00
|
|
|
options: {
|
2021-04-25 01:06:22 +00:00
|
|
|
filename: '[name].js',
|
|
|
|
inline: inlineWebWorkers
|
2017-02-11 06:50:16 +00:00
|
|
|
}
|
|
|
|
}
|
2021-04-25 01:06:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.js?$/,
|
|
|
|
exclude: /(node_modules|JsLibraries)/,
|
|
|
|
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',
|
|
|
|
corejs: 3
|
|
|
|
}
|
|
|
|
]
|
|
|
|
]
|
2019-07-17 01:31:39 +00:00
|
|
|
}
|
2019-03-03 19:29:12 +00:00
|
|
|
}
|
2021-04-25 01:06:22 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
|
|
|
|
// CSS Modules
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
exclude: /(node_modules|globals.css)/,
|
|
|
|
use: [
|
|
|
|
{ loader: MiniCssExtractPlugin.loader },
|
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
importLoaders: 1,
|
|
|
|
modules: {
|
|
|
|
localIdentName: '[name]/[local]/[hash:base64:5]'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
options: {
|
|
|
|
postcssOptions: {
|
|
|
|
config: 'frontend/postcss.config.js'
|
|
|
|
}
|
2018-01-13 02:01:27 +00:00
|
|
|
}
|
|
|
|
}
|
2021-04-25 01:06:22 +00:00
|
|
|
]
|
|
|
|
},
|
2017-02-11 06:50:16 +00:00
|
|
|
|
2021-04-25 01:06:22 +00:00
|
|
|
// Global styles
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
include: /(node_modules|globals.css)/,
|
|
|
|
use: [
|
|
|
|
'style-loader',
|
|
|
|
{
|
|
|
|
loader: 'css-loader'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2017-02-11 06:50:16 +00:00
|
|
|
|
2021-04-25 01:06:22 +00:00
|
|
|
// 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]'
|
|
|
|
}
|
2018-01-13 02:01:27 +00:00
|
|
|
}
|
2021-04-25 01:06:22 +00:00
|
|
|
]
|
|
|
|
},
|
2018-01-13 02:01:27 +00:00
|
|
|
|
2021-04-25 01:06:22 +00:00
|
|
|
{
|
|
|
|
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]'
|
|
|
|
}
|
2018-01-13 02:01:27 +00:00
|
|
|
}
|
2021-04-25 01:06:22 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
2017-02-11 06:50:16 +00:00
|
|
|
|
2021-04-25 01:06:22 +00:00
|
|
|
if (isProfiling) {
|
|
|
|
config.resolve.alias['react-dom$'] = 'react-dom/profiling';
|
|
|
|
config.resolve.alias['scheduler/tracing'] = 'scheduler/tracing-profiling';
|
2020-01-05 21:17:21 +00:00
|
|
|
|
2021-04-25 01:06:22 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
})
|
|
|
|
];
|
|
|
|
}
|
2020-01-05 21:17:21 +00:00
|
|
|
|
2021-04-25 01:06:22 +00:00
|
|
|
return config;
|
|
|
|
};
|