2020-03-24 14:22:29 +01:00
|
|
|
const path = require('path')
|
2022-10-22 10:31:34 +02:00
|
|
|
const fs = require('fs')
|
2020-03-24 14:22:29 +01:00
|
|
|
const webpack = require('webpack')
|
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
|
|
|
const VueLoaderPlugin = require('vue-loader/lib/plugin')
|
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin')
|
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
2022-09-13 03:28:36 +02:00
|
|
|
const JsonMinimizerPlugin = require('json-minimizer-webpack-plugin')
|
|
|
|
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')
|
2022-09-24 17:06:50 +02:00
|
|
|
const ProcessLocalesPlugin = require('./ProcessLocalesPlugin')
|
2020-03-24 14:22:29 +01:00
|
|
|
|
|
|
|
const { productName } = require('../package.json')
|
|
|
|
|
|
|
|
const isDevMode = process.env.NODE_ENV === 'development'
|
|
|
|
|
|
|
|
const config = {
|
|
|
|
name: 'web',
|
|
|
|
mode: process.env.NODE_ENV,
|
2022-10-06 16:47:47 +02:00
|
|
|
devtool: isDevMode ? 'eval-cheap-module-source-map' : false,
|
2020-03-24 14:22:29 +01:00
|
|
|
entry: {
|
|
|
|
web: path.join(__dirname, '../src/renderer/main.js'),
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
path: path.join(__dirname, '../dist/web'),
|
|
|
|
filename: '[name].js',
|
|
|
|
},
|
2022-10-06 16:47:47 +02:00
|
|
|
externals: {
|
2022-10-18 14:50:32 +02:00
|
|
|
electron: '{}',
|
|
|
|
ytpl: '{}',
|
|
|
|
ytsr: '{}'
|
2022-10-06 16:47:47 +02:00
|
|
|
},
|
2020-03-24 14:22:29 +01:00
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
2022-07-14 16:43:07 +02:00
|
|
|
test: /\.js$/,
|
2020-03-24 14:22:29 +01:00
|
|
|
use: 'babel-loader',
|
|
|
|
exclude: /node_modules/,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.vue$/,
|
2022-10-09 15:09:56 +02:00
|
|
|
loader: 'vue-loader'
|
2020-03-24 14:22:29 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.s(c|a)ss$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: MiniCssExtractPlugin.loader,
|
|
|
|
},
|
2022-09-12 02:34:58 +02:00
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
esModule: false
|
|
|
|
}
|
|
|
|
},
|
2020-04-18 05:17:45 +02:00
|
|
|
{
|
|
|
|
loader: 'sass-loader',
|
|
|
|
options: {
|
|
|
|
// eslint-disable-next-line
|
|
|
|
implementation: require('sass'),
|
|
|
|
sassOptions: {
|
|
|
|
indentedSyntax: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2020-03-24 14:22:29 +01:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
use: [
|
|
|
|
{
|
2022-09-02 15:19:06 +02:00
|
|
|
loader: MiniCssExtractPlugin.loader
|
2020-03-24 14:22:29 +01:00
|
|
|
},
|
2022-09-12 02:34:58 +02:00
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
esModule: false
|
|
|
|
}
|
|
|
|
}
|
2020-03-24 14:22:29 +01:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.html$/,
|
|
|
|
use: 'vue-html-loader',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(png|jpe?g|gif|tif?f|bmp|webp|svg)(\?.*)?$/,
|
2022-09-12 02:34:58 +02:00
|
|
|
type: 'asset/resource',
|
|
|
|
generator: {
|
|
|
|
filename: 'imgs/[name][ext]'
|
|
|
|
}
|
2020-03-24 14:22:29 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
|
2022-09-12 02:34:58 +02:00
|
|
|
type: 'asset/resource',
|
|
|
|
generator: {
|
|
|
|
filename: 'fonts/[name][ext]'
|
|
|
|
}
|
2020-03-24 14:22:29 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2022-09-13 03:28:36 +02: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
|
2022-09-24 17:06:50 +02:00
|
|
|
new JsonMinimizerPlugin({
|
|
|
|
exclude: /\/locales\/.*\.json/
|
|
|
|
}),
|
2022-09-13 03:28:36 +02:00
|
|
|
new CssMinimizerPlugin()
|
|
|
|
]
|
|
|
|
},
|
2020-03-24 14:22:29 +01:00
|
|
|
node: {
|
2022-10-06 16:47:47 +02:00
|
|
|
__dirname: true,
|
2020-03-24 14:22:29 +01:00
|
|
|
__filename: isDevMode,
|
|
|
|
},
|
|
|
|
plugins: [
|
2022-09-15 10:59:09 +02:00
|
|
|
new webpack.DefinePlugin({
|
|
|
|
'process.env.PRODUCT_NAME': JSON.stringify(productName),
|
|
|
|
'process.env.IS_ELECTRON': false
|
|
|
|
}),
|
2022-10-06 16:47:47 +02:00
|
|
|
new webpack.ProvidePlugin({
|
|
|
|
process: 'process/browser',
|
|
|
|
Buffer: ['buffer', 'Buffer'],
|
|
|
|
}),
|
2020-03-24 14:22:29 +01:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
excludeChunks: ['processTaskWorker'],
|
|
|
|
filename: 'index.html',
|
|
|
|
template: path.resolve(__dirname, '../src/index.ejs'),
|
|
|
|
nodeModules: false,
|
|
|
|
}),
|
|
|
|
new VueLoaderPlugin(),
|
|
|
|
new MiniCssExtractPlugin({
|
2020-11-24 03:53:49 +01:00
|
|
|
filename: isDevMode ? '[name].css' : '[name].[contenthash].css',
|
|
|
|
chunkFilename: isDevMode ? '[id].css' : '[id].[contenthash].css',
|
2020-03-24 14:22:29 +01:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
2022-11-09 13:34:40 +01:00
|
|
|
vue$: 'vue/dist/vue.esm.js'
|
2020-03-24 14:22:29 +01:00
|
|
|
},
|
2022-10-06 16:47:47 +02:00
|
|
|
fallback: {
|
|
|
|
buffer: require.resolve('buffer/'),
|
|
|
|
dns: require.resolve('browserify/lib/_empty.js'),
|
|
|
|
fs: require.resolve('browserify/lib/_empty.js'),
|
|
|
|
http: require.resolve('stream-http'),
|
|
|
|
https: require.resolve('https-browserify'),
|
|
|
|
net: require.resolve('browserify/lib/_empty.js'),
|
|
|
|
os: require.resolve('os-browserify/browser.js'),
|
|
|
|
path: require.resolve('path-browserify'),
|
|
|
|
stream: require.resolve('stream-browserify'),
|
|
|
|
timers: require.resolve('timers-browserify'),
|
|
|
|
tls: require.resolve('browserify/lib/_empty.js'),
|
2022-11-02 03:08:28 +01:00
|
|
|
vm: require.resolve('vm-browserify'),
|
|
|
|
zlib: require.resolve('browserify-zlib')
|
2022-10-06 16:47:47 +02:00
|
|
|
},
|
2022-11-09 13:34:40 +01:00
|
|
|
extensions: ['.js', '.vue']
|
2020-03-24 14:22:29 +01:00
|
|
|
},
|
|
|
|
target: 'web',
|
|
|
|
}
|
|
|
|
|
2022-10-18 14:50:32 +02:00
|
|
|
const processLocalesPlugin = new ProcessLocalesPlugin({
|
|
|
|
compress: false,
|
|
|
|
inputDir: path.join(__dirname, '../static/locales'),
|
|
|
|
outputDir: 'static/locales',
|
|
|
|
})
|
|
|
|
|
|
|
|
config.plugins.push(
|
|
|
|
processLocalesPlugin,
|
|
|
|
new webpack.DefinePlugin({
|
2022-10-22 10:31:34 +02:00
|
|
|
'process.env.LOCALE_NAMES': JSON.stringify(processLocalesPlugin.localeNames),
|
|
|
|
'process.env.GEOLOCATION_NAMES': JSON.stringify(fs.readdirSync(path.join(__dirname, '..', 'static', 'geolocations')))
|
2022-10-18 14:50:32 +02:00
|
|
|
}),
|
|
|
|
new CopyWebpackPlugin({
|
|
|
|
patterns: [
|
|
|
|
{
|
|
|
|
from: path.join(__dirname, '../static/pwabuilder-sw.js'),
|
|
|
|
to: path.join(__dirname, '../dist/web/pwabuilder-sw.js'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
from: path.join(__dirname, '../static'),
|
|
|
|
to: path.join(__dirname, '../dist/web/static'),
|
|
|
|
globOptions: {
|
|
|
|
dot: true,
|
|
|
|
ignore: ['**/.*', '**/locales/**', '**/pwabuilder-sw.js', '**/dashFiles/**', '**/storyboards/**'],
|
2020-05-23 23:29:42 +02:00
|
|
|
},
|
2022-10-18 14:50:32 +02:00
|
|
|
},
|
|
|
|
]
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2020-03-24 14:22:29 +01:00
|
|
|
|
|
|
|
module.exports = config
|