2020-02-16 18:30:00 +00:00
|
|
|
const path = require('path')
|
|
|
|
const webpack = require('webpack')
|
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
|
|
|
const VueLoaderPlugin = require('vue-loader/lib/plugin')
|
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
2022-09-13 01:28:36 +00:00
|
|
|
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')
|
2020-02-16 18:30:00 +00:00
|
|
|
|
2022-09-06 02:29:10 +00:00
|
|
|
const { productName } = require('../package.json')
|
2020-02-16 18:30:00 +00:00
|
|
|
|
|
|
|
const isDevMode = process.env.NODE_ENV === 'development'
|
|
|
|
|
|
|
|
const config = {
|
|
|
|
name: 'renderer',
|
|
|
|
mode: process.env.NODE_ENV,
|
2021-03-03 03:51:01 +00:00
|
|
|
devtool: isDevMode ? 'eval-cheap-module-source-map' : false,
|
2020-02-16 18:30:00 +00:00
|
|
|
entry: {
|
|
|
|
renderer: path.join(__dirname, '../src/renderer/main.js'),
|
|
|
|
},
|
2021-06-19 17:58:56 +00:00
|
|
|
infrastructureLogging: {
|
|
|
|
// Only warnings and errors
|
|
|
|
// level: 'none' disable logging
|
|
|
|
// Please read https://webpack.js.org/configuration/other-options/#infrastructurelogginglevel
|
|
|
|
level: isDevMode ? 'info' : 'none'
|
|
|
|
},
|
2020-02-16 18:30:00 +00:00
|
|
|
output: {
|
|
|
|
libraryTarget: 'commonjs2',
|
|
|
|
path: path.join(__dirname, '../dist'),
|
|
|
|
filename: '[name].js',
|
|
|
|
},
|
2022-09-06 02:29:10 +00:00
|
|
|
// webpack spits out errors while inlining ytpl and ytsr as
|
|
|
|
// they dynamically import their package.json file to extract the bug report URL
|
|
|
|
// the error: "Critical dependency: the request of a dependency is an expression"
|
|
|
|
externals: ['ytpl', 'ytsr'],
|
2020-02-16 18:30:00 +00:00
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
2022-07-14 14:43:07 +00:00
|
|
|
test: /\.js$/,
|
2020-02-16 18:30:00 +00:00
|
|
|
use: 'babel-loader',
|
|
|
|
exclude: /node_modules/,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.node$/,
|
2021-03-03 03:51:01 +00:00
|
|
|
loader: 'node-loader',
|
2020-02-16 18:30:00 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.vue$/,
|
|
|
|
loader: 'vue-loader',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.s(c|a)ss$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: MiniCssExtractPlugin.loader,
|
|
|
|
},
|
2022-09-12 00:34:58 +00:00
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
esModule: false
|
|
|
|
}
|
|
|
|
},
|
2020-02-16 18:30:00 +00:00
|
|
|
{
|
|
|
|
loader: 'sass-loader',
|
|
|
|
options: {
|
|
|
|
// eslint-disable-next-line
|
|
|
|
implementation: require('sass'),
|
2020-03-24 14:34:55 +00:00
|
|
|
sassOptions: {
|
|
|
|
indentedSyntax: true
|
|
|
|
}
|
|
|
|
}
|
2020-02-16 18:30:00 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
use: [
|
|
|
|
{
|
2022-09-02 13:19:06 +00:00
|
|
|
loader: MiniCssExtractPlugin.loader
|
2020-02-16 18:30:00 +00:00
|
|
|
},
|
2022-09-12 00:34:58 +00:00
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
esModule: false
|
|
|
|
}
|
|
|
|
}
|
2020-02-16 18:30:00 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(png|jpe?g|gif|tif?f|bmp|webp|svg)(\?.*)?$/,
|
2022-09-12 00:34:58 +00:00
|
|
|
type: 'asset/resource',
|
|
|
|
generator: {
|
|
|
|
filename: 'imgs/[name][ext]'
|
|
|
|
}
|
2020-02-16 18:30:00 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
|
2022-09-12 00:34:58 +00:00
|
|
|
type: 'asset/resource',
|
|
|
|
generator: {
|
|
|
|
filename: 'fonts/[name][ext]'
|
|
|
|
}
|
2020-02-16 18:30:00 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2022-09-13 01:28:36 +00:00
|
|
|
// webpack defaults to only optimising the production builds, so having this here is fine
|
|
|
|
optimization: {
|
|
|
|
minimizer: [
|
|
|
|
'...', // extend webpack's list instead of overwriting it
|
|
|
|
new CssMinimizerPlugin()
|
|
|
|
]
|
|
|
|
},
|
2020-02-16 18:30:00 +00:00
|
|
|
node: {
|
|
|
|
__dirname: isDevMode,
|
|
|
|
__filename: isDevMode,
|
2021-03-03 03:51:01 +00:00
|
|
|
global: isDevMode,
|
2020-02-16 18:30:00 +00:00
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
// new WriteFilePlugin(),
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
excludeChunks: ['processTaskWorker'],
|
|
|
|
filename: 'index.html',
|
|
|
|
template: path.resolve(__dirname, '../src/index.ejs'),
|
|
|
|
nodeModules: isDevMode
|
|
|
|
? path.resolve(__dirname, '../node_modules')
|
|
|
|
: false,
|
|
|
|
}),
|
|
|
|
new VueLoaderPlugin(),
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env.PRODUCT_NAME': JSON.stringify(productName),
|
|
|
|
}),
|
|
|
|
new MiniCssExtractPlugin({
|
2020-11-24 02:53:49 +00:00
|
|
|
filename: isDevMode ? '[name].css' : '[name].[contenthash].css',
|
|
|
|
chunkFilename: isDevMode ? '[id].css' : '[id].[contenthash].css',
|
2020-02-16 18:30:00 +00:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
vue$: 'vue/dist/vue.common.js',
|
|
|
|
'@': path.join(__dirname, '../src/'),
|
|
|
|
src: path.join(__dirname, '../src/'),
|
|
|
|
icons: path.join(__dirname, '../_icons/'),
|
2020-07-11 22:36:42 +00:00
|
|
|
images: path.join(__dirname, '../src/renderer/assets/img/'),
|
2020-08-06 03:39:00 +00:00
|
|
|
static: path.join(__dirname, '../static/'),
|
2020-02-16 18:30:00 +00:00
|
|
|
},
|
2022-05-31 20:15:44 +00:00
|
|
|
extensions: ['.js', '.vue', '.json'],
|
2020-02-16 18:30:00 +00:00
|
|
|
},
|
|
|
|
target: 'electron-renderer',
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adjust rendererConfig for production settings
|
|
|
|
*/
|
|
|
|
if (isDevMode) {
|
|
|
|
// any dev only config
|
2020-03-24 13:22:29 +00:00
|
|
|
config.plugins.push(
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
__static: `"${path.join(__dirname, '../static').replace(/\\/g, '\\\\')}"`,
|
|
|
|
})
|
|
|
|
)
|
2020-02-16 18:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = config
|