Sonarr/frontend/build/webpack.config.js

262 lines
5.9 KiB
JavaScript
Raw Normal View History

/* eslint-disable filenames/match-exported */
2017-02-11 06:50:16 +00:00
const path = require('path');
const webpack = require('webpack');
const CopyPlugin = require('copy-webpack-plugin');
2019-08-19 18:37:27 +00:00
const HtmlWebpackPlugin = require('html-webpack-plugin');
const LiveReloadPlugin = require('webpack-livereload-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserPlugin = require('terser-webpack-plugin');
2017-02-11 06:50:16 +00:00
const uiFolder = 'UI';
2019-03-03 19:29:12 +00:00
const frontendFolder = path.join(__dirname, '..');
2019-03-06 02:07:51 +00:00
const srcFolder = path.join(frontendFolder, 'src');
2017-02-11 06:50:16 +00:00
const isProduction = process.argv.indexOf('--production') > -1;
const isProfiling = isProduction && process.argv.indexOf('--profile') > -1;
2020-10-03 22:25:48 +00:00
const inlineWebWorkers = 'no-fallback';
2017-02-11 06:50:16 +00:00
2019-08-19 18:37:27 +00:00
const distFolder = path.resolve(frontendFolder, '..', '_output', uiFolder);
2019-03-03 19:29:12 +00:00
console.log('Source Folder:', srcFolder);
2019-08-19 18:37:27 +00:00
console.log('Output Folder:', distFolder);
2017-02-11 06:50:16 +00:00
console.log('isProduction:', isProduction);
2020-03-01 21:31:12 +00:00
console.log('isProfiling:', isProfiling);
2017-02-11 06:50:16 +00:00
const config = {
2019-03-03 19:29:12 +00:00
mode: isProduction ? 'production' : 'development',
devtool: 'source-map',
2018-01-13 02:01:27 +00:00
2017-02-11 06:50:16 +00:00
stats: {
children: false
},
2018-01-13 02:01:27 +00:00
2017-02-11 06:50:16 +00:00
watchOptions: {
ignored: /node_modules/
},
2018-01-13 02:01:27 +00:00
2017-02-11 06:50:16 +00:00
entry: {
index: 'index.js'
},
2018-01-13 02:01:27 +00:00
2017-02-11 06:50:16 +00:00
resolve: {
2018-01-13 02:01:27 +00:00
modules: [
2019-03-03 19:29:12 +00:00
srcFolder,
path.join(srcFolder, 'Shims'),
2018-01-13 02:01:27 +00:00
'node_modules'
],
alias: {
jquery: 'jquery/src/jquery'
}
2017-02-11 06:50:16 +00:00
},
2018-01-13 02:01:27 +00:00
2017-02-11 06:50:16 +00:00
output: {
2019-08-19 18:37:27 +00:00
path: distFolder,
publicPath: '/',
2019-08-19 18:37:27 +00:00
filename: '[name].js',
2018-01-13 02:01:27 +00:00
sourceMapFilename: '[file].map'
2017-02-11 06:50:16 +00:00
},
2018-01-13 02:01:27 +00:00
2019-03-03 19:29:12 +00:00
optimization: {
moduleIds: 'deterministic',
2019-08-19 18:37:27 +00:00
chunkIds: 'named',
splitChunks: {
chunks: 'initial',
name: 'vendors'
2019-08-19 18:37:27 +00:00
}
},
performance: {
hints: false
2019-03-03 19:29:12 +00:00
},
plugins: [
new webpack.DefinePlugin({
__DEV__: !isProduction,
'process.env.NODE_ENV': isProduction ? JSON.stringify('production') : JSON.stringify('development')
}),
new MiniCssExtractPlugin({
filename: 'Content/styles.css'
}),
new HtmlWebpackPlugin({
template: 'frontend/src/index.html',
filename: 'index.html',
publicPath: '/'
}),
new CopyPlugin({
patterns: [
// HTML
{
from: 'frontend/src/*.html',
to: path.join(distFolder, '[name][ext]'),
globOptions: {
ignore: ['**/index.html']
}
},
// Fonts
{
from: 'frontend/src/Content/Fonts/*.*',
to: path.join(distFolder, 'Content/Fonts', '[name][ext]')
},
// Icon Images
{
from: 'frontend/src/Content/Images/Icons/*.*',
to: path.join(distFolder, 'Content/Images/Icons', '[name][ext]')
},
// Images
{
from: 'frontend/src/Content/Images/*.*',
to: path.join(distFolder, 'Content/Images', '[name][ext]')
},
// Robots
{
from: 'frontend/src/Content/robots.txt',
to: path.join(distFolder, 'Content', '[name][ext]')
}
]
}),
new LiveReloadPlugin()
],
2018-01-13 02:01:27 +00:00
2017-02-11 06:50:16 +00:00
resolveLoader: {
2018-01-13 02:01:27 +00:00
modules: [
2017-02-11 06:50:16 +00:00
'node_modules',
'frontend/build/webpack/'
2017-02-11 06:50:16 +00:00
]
},
2018-01-13 02:01:27 +00:00
2017-02-11 06:50:16 +00:00
module: {
2018-01-13 02:01:27 +00:00
rules: [
{
test: /\.worker\.js$/,
use: {
loader: 'worker-loader',
options: {
2020-10-03 22:25:48 +00:00
filename: '[name].js',
inline: inlineWebWorkers
}
}
},
2017-02-11 06:50:16 +00:00
{
test: /\.js?$/,
exclude: /(node_modules|JsLibraries)/,
2019-03-03 19:29:12 +00:00
use: [
{
loader: 'babel-loader',
options: {
configFile: `${frontendFolder}/babel.config.js`,
2019-03-06 02:07:51 +00:00
envName: isProduction ? 'production' : 'development',
presets: [
[
'@babel/preset-env',
{
modules: false,
loose: true,
debug: false,
useBuiltIns: 'entry',
2019-07-17 01:52:17 +00:00
corejs: 3
2019-03-06 02:07:51 +00:00
}
]
]
2017-02-11 06:50:16 +00:00
}
}
2019-03-03 19:29:12 +00:00
]
2017-02-11 06:50:16 +00:00
},
// CSS Modules
{
test: /\.css$/,
exclude: /(node_modules|globals.css)/,
2019-03-03 19:29:12 +00:00
use: [
{ loader: MiniCssExtractPlugin.loader },
{
loader: 'css-loader',
options: {
importLoaders: 1,
2019-07-17 01:31:39 +00:00
modules: {
localIdentName: '[name]/[local]/[hash:base64:5]'
}
2019-03-03 19:29:12 +00:00
}
},
{
loader: 'postcss-loader',
options: {
2021-04-24 20:51:43 +00:00
postcssOptions: {
config: 'frontend/postcss.config.js'
2018-01-13 02:01:27 +00:00
}
}
2019-03-03 19:29:12 +00:00
}
]
2017-02-11 06:50:16 +00:00
},
// Global styles
{
test: /\.css$/,
include: /(node_modules|globals.css)/,
2018-01-13 02:01:27 +00:00
use: [
'style-loader',
{
loader: 'css-loader'
}
]
2017-02-11 06:50:16 +00:00
},
// Fonts
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
2018-01-13 02:01:27 +00:00
use: [
{
loader: 'url-loader',
options: {
limit: 10240,
mimetype: 'application/font-woff',
emitFile: false,
name: 'Content/Fonts/[name].[ext]'
}
}
]
2017-02-11 06:50:16 +00:00
},
2018-01-13 02:01:27 +00:00
2017-02-11 06:50:16 +00:00
{
test: /\.(ttf|eot|eot?#iefix|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
2018-01-13 02:01:27 +00:00
use: [
{
loader: 'file-loader',
options: {
emitFile: false,
name: 'Content/Fonts/[name].[ext]'
}
}
]
2017-02-11 06:50:16 +00: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
}
})
];
}
module.exports = config;
/* eslint-enable filenames/match-exported */