summaryrefslogtreecommitdiff
path: root/electron/service/config
diff options
context:
space:
mode:
authorrejbasket <39080670+rejbasket@users.noreply.github.com>2023-05-22 22:33:19 +0200
committerGitHub <noreply@github.com>2023-05-22 22:33:19 +0200
commitef6f6580df6e8fbce913eecc1fe7e0f8caf1315b (patch)
treec1119a5d1affd44ad27e60cc6981ac98534c518d /electron/service/config
parentda54f104e6bf5d0e98f7479cf1d060c76e0b01f2 (diff)
Update electron version to v14.2.9 (#2214)
Authored-by: rejbasket Co-authored-by: Kaalleen Co-authored-by: Lex Neva
Diffstat (limited to 'electron/service/config')
-rw-r--r--electron/service/config/base.js126
-rw-r--r--electron/service/config/css.js72
-rw-r--r--electron/service/config/dev.js43
-rw-r--r--electron/service/config/main.js73
-rw-r--r--electron/service/config/prod.js41
-rw-r--r--electron/service/config/renderer.js45
-rw-r--r--electron/service/config/terserOptions.js42
7 files changed, 442 insertions, 0 deletions
diff --git a/electron/service/config/base.js b/electron/service/config/base.js
new file mode 100644
index 00000000..8743f364
--- /dev/null
+++ b/electron/service/config/base.js
@@ -0,0 +1,126 @@
+'use strict'
+
+const { DefinePlugin, EnvironmentPlugin } = require('webpack')
+const { VueLoaderPlugin } = require('vue-loader')
+const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
+const HTMLPlugin = require('html-webpack-plugin')
+const { VuetifyPlugin } = require('webpack-plugin-vuetify')
+
+const resolveClientEnv = require('../utils/resolveClientEnv')
+const paths = require('../utils/paths')
+
+const config = require('../project.config')
+
+const isProd = process.env.NODE_ENV === 'production'
+
+module.exports = {
+ context: process.cwd(),
+
+ output: {
+ path: paths.resolve(config.outputDir),
+ publicPath: config.dev.publicPath,
+ filename: '[name].js',
+ },
+
+ resolve: {
+ alias: {
+ '@': paths.resolve('src'),
+ },
+ extensions: ['.ts', '.tsx', '.js', '.jsx', '.vue', '.json', 'html', 'ejs'],
+ },
+
+ plugins: [
+ new VueLoaderPlugin(),
+ new EnvironmentPlugin(['NODE_ENV']),
+ new CaseSensitivePathsPlugin(),
+ new HTMLPlugin({
+ template: paths.resolve('src/index.html'),
+ templateParameters: {
+ ...resolveClientEnv(
+ { publicPath: isProd ? config.build.publicPath : config.dev.publicPath },
+ false /* raw */
+ ),
+ },
+ }),
+ new VuetifyPlugin({ autoImport: true }),
+ new DefinePlugin({
+ // vue3 feature flags <http://link.vuejs.org/feature-flags>
+ __VUE_OPTIONS_API__: 'true',
+ __VUE_PROD_DEVTOOLS__: 'false',
+
+ ...resolveClientEnv({
+ publicPath: isProd ? config.build.publicPath : config.dev.publicPath,
+ }),
+ }),
+ ],
+
+ module: {
+ noParse: /^(vue|vue-router)$/,
+
+ rules: [
+ {
+ test: /\.vue$/,
+ loader: 'vue-loader',
+ },
+ // babel
+ {
+ test: /\.m?jsx?$/,
+ exclude: (file) => {
+ // always transpile js in vue files
+ if (/\.vue\.jsx?$/.test(file)) {
+ return false
+ }
+ // Don't transpile node_modules
+ return /node_modules/.test(file)
+ },
+ use: ['thread-loader', 'babel-loader'],
+ },
+
+ // ts
+ {
+ test: /\.tsx?$/,
+ use: [
+ 'thread-loader',
+ 'babel-loader',
+ {
+ loader: 'ts-loader',
+ options: {
+ transpileOnly: true,
+ appendTsSuffixTo: ['\\.vue$'],
+ happyPackMode: true,
+ },
+ },
+ ],
+ },
+
+ // images
+ {
+ test: /\.(png|jpe?g|gif|webp)(\?.*)?$/,
+ type: 'asset',
+ generator: { filename: 'img/[contenthash:8][ext][query]' },
+ },
+
+ // do not base64-inline SVGs.
+ // https://github.com/facebookincubator/create-react-app/pull/1180
+ {
+ test: /\.(svg)(\?.*)?$/,
+ type: 'asset/resource',
+ generator: { filename: 'img/[contenthash:8][ext][query]' },
+ },
+
+ // media
+ {
+ test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
+ type: 'asset',
+ generator: { filename: 'media/[contenthash:8][ext][query]' },
+ },
+
+ // fonts
+ {
+ test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/i,
+ type: 'asset',
+ generator: { filename: 'fonts/[contenthash:8][ext][query]' },
+ },
+ ],
+ },
+}
diff --git a/electron/service/config/css.js b/electron/service/config/css.js
new file mode 100644
index 00000000..3fb5893e
--- /dev/null
+++ b/electron/service/config/css.js
@@ -0,0 +1,72 @@
+'use strict'
+
+const MiniCssExtractPlugin = require('mini-css-extract-plugin')
+
+const isProd = process.env.NODE_ENV === 'production'
+
+const plugins = []
+if (isProd) {
+ const filename = 'css/[name].[contenthash:8].css'
+
+ plugins.push(
+ new MiniCssExtractPlugin({
+ filename,
+ chunkFilename: filename,
+ })
+ )
+}
+
+const genStyleRules = () => {
+ const cssLoader = {
+ loader: 'css-loader',
+ options: {
+ // how many loaders before css-loader should be applied to [@import]ed resources.
+ // stylePostLoader injected by vue-loader + postcss-loader
+ importLoaders: 1 + 1,
+ esModule: false, // css-loader using ES Modules as default in v4, but vue-style-loader support cjs only.
+ },
+ }
+ const postcssLoader = {
+ loader: 'postcss-loader',
+ options: {
+ postcssOptions: {
+ plugins: [require('autoprefixer')]
+ },
+ },
+ }
+ const extractPluginLoader = {
+ loader: MiniCssExtractPlugin.loader,
+ }
+ const vueStyleLoader = {
+ loader: 'vue-style-loader',
+ }
+
+ function createCSSRule(test, loader, loaderOptions) {
+ const loaders = [cssLoader, postcssLoader]
+
+ if (isProd) {
+ loaders.unshift(extractPluginLoader)
+ } else {
+ loaders.unshift(vueStyleLoader)
+ }
+
+ if (loader) {
+ loaders.push({ loader, options: loaderOptions })
+ }
+
+ return { test, use: loaders }
+ }
+
+ return [
+ createCSSRule(/\.css$/),
+ createCSSRule(/\.p(ost)?css$/),
+ createCSSRule(/\.scss$/, 'sass-loader')
+ ]
+}
+
+module.exports = {
+ plugins,
+ module: {
+ rules: genStyleRules(),
+ },
+}
diff --git a/electron/service/config/dev.js b/electron/service/config/dev.js
new file mode 100644
index 00000000..42a82b37
--- /dev/null
+++ b/electron/service/config/dev.js
@@ -0,0 +1,43 @@
+'use strict'
+
+const { merge } = require('webpack-merge')
+
+const baseWebpackConfig = require('./base')
+const cssWebpackConfig = require('./css')
+const config = require('../project.config')
+const { ProvidePlugin, DefinePlugin } = require('webpack')
+
+
+module.exports = merge(baseWebpackConfig, cssWebpackConfig, {
+ entry: {
+ main: './src/renderer/main.js'
+ },
+
+ mode: 'development',
+
+ devtool: 'eval-cheap-module-source-map',
+
+ devServer: {
+ watchFiles: ['src/**/*'],
+ historyApiFallback: {
+ rewrites: [{ from: /./, to: '/index.html' }],
+ },
+ devMiddleware: {
+ publicPath: config.dev.publicPath,
+ },
+ open: false,
+ host: '0.0.0.0',
+ port: 'auto',
+ liveReload: true,
+ },
+
+ infrastructureLogging: {
+ level: 'warn',
+ },
+
+ stats: {
+ assets: false,
+ modules: false,
+ errorDetails: false,
+ },
+})
diff --git a/electron/service/config/main.js b/electron/service/config/main.js
new file mode 100644
index 00000000..3083dea0
--- /dev/null
+++ b/electron/service/config/main.js
@@ -0,0 +1,73 @@
+'use strict'
+
+const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
+const config = require('../project.config')
+
+const resolveClientEnv = require('../utils/resolveClientEnv')
+const paths = require('../utils/paths')
+const { merge } = require('webpack-merge')
+const TerserPlugin = require('terser-webpack-plugin')
+const cssWebpackConfig = require('./css')
+const terserOptions = require('./terserOptions')
+const isProd = process.env.NODE_ENV === 'production'
+
+module.exports = merge(cssWebpackConfig, {
+ context: process.cwd(),
+ mode: 'production',
+ entry: {
+ main: './src/main/index.js',
+ preload: './src/main/preload.js',
+ },
+
+ node: {
+ __dirname: false,
+ },
+
+ optimization: {
+ minimize: true,
+ minimizer: [new TerserPlugin(terserOptions())],
+ moduleIds: 'named',
+ },
+ target: ['electron-main'],
+
+ output: {
+ path: paths.resolve(config.outputDir),
+ publicPath: config.dev.publicPath,
+ filename: '[name].js',
+ },
+
+ resolve: {
+ alias: {
+ '@': paths.resolve('src'),
+ },
+ extensions: ['.ts', '.tsx', '.js', '.jsx', '.vue', '.json', 'html', 'ejs'],
+ },
+
+ plugins: [
+ new CaseSensitivePathsPlugin(),
+ ],
+
+ module: {
+ noParse: /^(vue|vue-router)$/,
+
+ rules: [
+ // ts
+ {
+ test: /\.tsx?$/,
+ use: [
+ 'thread-loader',
+ 'babel-loader',
+ {
+ loader: 'ts-loader',
+ options: {
+ transpileOnly: true,
+ appendTsSuffixTo: ['\\.vue$'],
+ happyPackMode: true,
+ },
+ },
+ ],
+ },
+ ],
+ },
+}
+) \ No newline at end of file
diff --git a/electron/service/config/prod.js b/electron/service/config/prod.js
new file mode 100644
index 00000000..1d9e8726
--- /dev/null
+++ b/electron/service/config/prod.js
@@ -0,0 +1,41 @@
+'use strict'
+
+const { merge } = require('webpack-merge')
+const TerserPlugin = require('terser-webpack-plugin')
+
+const baseWebpackConfig = require('./base')
+const cssWebpackConfig = require('./css')
+const config = require('../project.config')
+const terserOptions = require('./terserOptions')
+
+module.exports = merge(baseWebpackConfig, cssWebpackConfig, {
+ mode: 'production',
+
+ output: {
+ publicPath: config.build.publicPath,
+ },
+
+ optimization: {
+ minimize: true,
+ minimizer: [new TerserPlugin(terserOptions())],
+ moduleIds: 'deterministic',
+ moduleIds: 'named',
+ splitChunks: {
+ cacheGroups: {
+ defaultVendors: {
+ name: `chunk-vendors`,
+ test: /[\\/]node_modules[\\/]/,
+ priority: -10,
+ chunks: 'initial',
+ },
+ common: {
+ name: `chunk-common`,
+ minChunks: 2,
+ priority: -20,
+ chunks: 'initial',
+ reuseExistingChunk: true,
+ },
+ },
+ },
+ },
+})
diff --git a/electron/service/config/renderer.js b/electron/service/config/renderer.js
new file mode 100644
index 00000000..cf3fab01
--- /dev/null
+++ b/electron/service/config/renderer.js
@@ -0,0 +1,45 @@
+'use strict'
+
+const { merge } = require('webpack-merge')
+const TerserPlugin = require('terser-webpack-plugin')
+
+const baseWebpackConfig = require('./base')
+const cssWebpackConfig = require('./css')
+const config = require('../project.config')
+const terserOptions = require('./terserOptions')
+
+module.exports = merge(baseWebpackConfig, cssWebpackConfig, {
+ mode: 'production',
+ entry: {
+ renderer: './src/renderer/main.js',
+ },
+
+ output: {
+ publicPath: config.build.publicPath,
+ },
+
+ optimization: {
+ minimize: true,
+ minimizer: [new TerserPlugin(terserOptions())],
+ moduleIds: 'deterministic',
+ moduleIds: 'named',
+ splitChunks: {
+ cacheGroups: {
+ defaultVendors: {
+ name: `chunk-vendors`,
+ test: /[\\/]node_modules[\\/]/,
+ priority: -10,
+ chunks: 'initial',
+ },
+ common: {
+ name: `chunk-common`,
+ minChunks: 2,
+ priority: -20,
+ chunks: 'initial',
+ reuseExistingChunk: true,
+ },
+ },
+ },
+ },
+ target: ['electron-renderer'],
+})
diff --git a/electron/service/config/terserOptions.js b/electron/service/config/terserOptions.js
new file mode 100644
index 00000000..134a3258
--- /dev/null
+++ b/electron/service/config/terserOptions.js
@@ -0,0 +1,42 @@
+'use strict'
+
+module.exports = (options) => ({
+ terserOptions: {
+ compress: {
+ // turn off flags with small gains to speed up minification
+ arrows: false,
+ collapse_vars: false, // 0.3kb
+ comparisons: false,
+ computed_props: false,
+ hoist_funs: false,
+ hoist_props: false,
+ hoist_vars: false,
+ inline: false,
+ loops: false,
+ negate_iife: false,
+ properties: false,
+ reduce_funcs: false,
+ reduce_vars: false,
+ switches: false,
+ toplevel: false,
+ typeofs: false,
+
+ // a few flags with noticable gains/speed ratio
+ // numbers based on out of the box vendor bundle
+ booleans: true, // 0.7kb
+ if_return: true, // 0.4kb
+ sequences: true, // 0.7kb
+ unused: true, // 2.3kb
+
+ // required features to drop conditional branches
+ conditionals: true,
+ dead_code: true,
+ evaluate: true,
+ },
+ mangle: {
+ safari10: true,
+ },
+ },
+ // parallel: options.parallel,
+ extractComments: false,
+})