1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2024-12-27 09:14:44 +01:00
Whalebird-desktop-client-ma.../.electron-vue/webpack.renderer.config.js
2023-01-14 02:00:51 +09:00

263 lines
6.1 KiB
JavaScript

'use strict'
process.env.BABEL_ENV = 'renderer'
const path = require('path')
const { dependencies } = require('../package.json')
const webpack = require('webpack')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { VueLoaderPlugin } = require('vue-loader')
let rendererConfig = {
entry: {
renderer: path.join(__dirname, '../src/renderer/main.ts')
},
module: {
rules: [
{
test: /\.m?js$/,
resolve: {
fullySpecified: false
}
},
{
test: /\.vue$/,
use: {
loader: 'vue-loader',
options: {
extractCSS: process.env.NODE_ENV === 'production',
esModule: true,
optimizeSSR: false
}
}
},
{
test: /\.scss$/,
use: [
'vue-style-loader',
{
loader: 'css-loader',
options: {
modules: false,
esModule: false
}
},
'sass-loader'
]
},
{
test: /\.sass$/,
use: [
'vue-style-loader',
{
loader: 'css-loader',
options: {
modules: false,
esModule: false
}
},
'sass-loader?indentedSyntax'
]
},
{
test: /\.less$/,
use: [
'vue-style-loader',
{
loader: 'css-loader',
options: {
modules: false,
esModule: false
}
},
'less-loader'
]
},
{
test: /\.css$/,
use: [
'vue-style-loader',
{
loader: 'css-loader',
options: {
modules: false,
esModule: false
}
}
]
},
{
test: /\.html$/,
use: 'vue-html-loader'
},
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader?cacheDirectory'
},
{
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/],
transpileOnly: true
}
}
]
},
{
test: /\.js$/,
use: 'babel-loader?cacheDirectory',
exclude: /node_modules/
},
{
test: /\.node$/,
use: 'node-loader'
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
use: {
loader: 'url-loader',
options: {
limit: 10000,
name: 'imgs/[name]--[folder].[ext]',
esModule: false
}
}
},
{
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: 'media/[name]--[folder].[ext]'
}
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
use: {
loader: 'url-loader',
options: {
limit: 10000,
name: 'fonts/[name]--[folder].[ext]'
}
}
},
{
test: /\.json$/,
exclude: /node_modules/,
use: 'json-loader',
type: 'javascript/auto'
}
]
},
node: {
__dirname: process.env.NODE_ENV !== 'production',
__filename: process.env.NODE_ENV !== 'production'
},
devServer: {
hot: true,
hotOnly: true
},
plugins: [
new VueLoaderPlugin(),
new MiniCssExtractPlugin({ filename: 'styles.css' }),
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.resolve(__dirname, '../src/index.ejs'),
minify: {
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true
},
nodeModules: process.env.NODE_ENV !== 'production' ? path.resolve(__dirname, '../node_modules') : false
}),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.DefinePlugin({
'process.browser': true,
'process.env.NODE_DEBUG': false
}),
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer']
}),
new webpack.ProvidePlugin({
process: 'process/browser'
})
],
output: {
filename: '[name].js',
path: path.join(__dirname, '../dist/electron')
},
resolve: {
alias: {
// Same as tsconfig.json
'@': path.join(__dirname, '../src/renderer'),
'~': path.join(__dirname, '../')
},
extensions: ['.ts', '.js', '.vue', '.json', '.css', '.node'],
fallback: {
timers: require.resolve('timers-browserify'),
url: require.resolve('url/'),
assert: require.resolve('assert/'),
buffer: require.resolve('buffer/'),
os: require.resolve('os-browserify/browser'),
path: require.resolve('path-browserify'),
crypto: require.resolve('crypto-browserify'),
http: require.resolve('stream-http'),
https: require.resolve('https-browserify'),
stream: require.resolve('stream-browserify'),
zlib: require.resolve('browserify-zlib'),
net: false,
tls: false,
fs: false,
dns: false
}
},
target: 'web'
}
/**
* Adjust rendererConfig for development settings
*/
if (process.env.NODE_ENV !== 'production') {
rendererConfig.plugins.push(
new webpack.DefinePlugin({
__static: `"${path.join(__dirname, '../static').replace(/\\/g, '\\\\')}"`
})
)
rendererConfig.devtool = 'eval-cheap-module-source-map'
}
/**
* Adjust rendererConfig for production settings
*/
if (process.env.NODE_ENV === 'production') {
rendererConfig.mode = 'production'
rendererConfig.plugins.push(
new CopyWebpackPlugin({
patterns: [
{
from: path.join(__dirname, '../static'),
to: path.join(__dirname, '../dist/electron/static'),
globOptions: {
ignore: ['.*', '*~']
}
}
]
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"'
}),
new webpack.LoaderOptionsPlugin({
minimize: true
})
)
}
module.exports = rendererConfig