Whalebird-desktop-client-ma.../.electron-vue/webpack.renderer.config.js

200 lines
4.9 KiB
JavaScript
Raw Normal View History

2018-03-07 14:28:48 +01:00
'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')
2018-11-12 15:54:39 +01:00
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
2018-03-07 14:28:48 +01:00
const HtmlWebpackPlugin = require('html-webpack-plugin')
2018-11-12 15:54:39 +01:00
const { VueLoaderPlugin } = require('vue-loader')
2018-03-07 14:28:48 +01:00
let rendererConfig = {
devtool: '#cheap-module-eval-source-map',
entry: {
renderer: path.join(__dirname, '../src/renderer/main.ts')
2018-03-07 14:28:48 +01:00
},
module: {
rules: [
{
test: /\.(js|vue|ts)$/,
2018-03-07 14:28:48 +01:00
enforce: 'pre',
exclude: /node_modules/,
use: {
loader: 'eslint-loader',
options: {
formatter: require('eslint-friendly-formatter')
}
}
},
2018-11-12 15:54:39 +01:00
{
test: /\.scss$/,
use: ['vue-style-loader', 'css-loader', 'sass-loader']
},
{
test: /\.sass$/,
use: ['vue-style-loader', 'css-loader', 'sass-loader?indentedSyntax']
},
{
test: /\.less$/,
use: ['vue-style-loader', 'css-loader', 'less-loader']
},
2018-03-07 14:28:48 +01:00
{
test: /\.css$/,
2018-11-12 15:54:39 +01:00
use: ['vue-style-loader', 'css-loader']
2018-03-07 14:28:48 +01:00
},
{
test: /\.html$/,
use: 'vue-html-loader'
},
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader'
},
{
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/]
}
}
]
},
2018-03-07 14:28:48 +01:00
{
test: /\.js$/,
use: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.node$/,
use: 'node-loader'
},
{
test: /\.vue$/,
use: {
loader: 'vue-loader',
options: {
extractCSS: process.env.NODE_ENV === 'production',
loaders: {
js: 'ts-loader',
ts: 'ts-loader',
2018-03-07 14:28:48 +01:00
sass: 'vue-style-loader!css-loader!sass-loader?indentedSyntax=1',
2018-11-12 15:54:39 +01:00
scss: 'vue-style-loader!css-loader!sass-loader',
less: 'vue-style-loader!css-loader!less-loader'
2018-03-07 14:28:48 +01:00
}
}
}
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
use: {
loader: 'url-loader',
options: {
2018-03-07 14:28:48 +01:00
limit: 10000,
name: 'imgs/[name]--[folder].[ext]',
esModule: false
2018-03-07 14:28:48 +01:00
}
}
},
{
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',
query: {
limit: 10000,
name: 'fonts/[name]--[folder].[ext]'
}
}
},
{
test: /\.json$/,
exclude: /node_modules/,
use: 'json-loader',
type: 'javascript/auto'
2018-03-07 14:28:48 +01:00
}
]
},
node: {
__dirname: process.env.NODE_ENV !== 'production',
__filename: process.env.NODE_ENV !== 'production'
},
plugins: [
2018-11-12 15:54:39 +01:00
new VueLoaderPlugin(),
new MiniCssExtractPlugin({ filename: 'styles.css' }),
2018-03-07 14:28:48 +01:00
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
2018-03-07 14:28:48 +01:00
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin()
2018-03-07 14:28:48 +01:00
],
output: {
filename: '[name].js',
path: path.join(__dirname, '../dist/electron')
},
resolve: {
alias: {
2019-03-21 15:23:57 +01:00
// Same as tsconfig.json
2018-03-07 14:28:48 +01:00
'@': path.join(__dirname, '../src/renderer'),
2018-08-12 13:40:01 +02:00
'~': path.join(__dirname, '../'),
vue$: 'vue/dist/vue.esm.js'
2018-03-07 14:28:48 +01:00
},
2019-03-21 15:23:57 +01:00
extensions: ['.ts', '.js', '.vue', '.json', '.css', '.node']
2018-03-07 14:28:48 +01:00
},
target: 'electron-renderer'
}
/**
* Adjust rendererConfig for development settings
*/
if (process.env.NODE_ENV !== 'production') {
rendererConfig.plugins.push(
new webpack.DefinePlugin({
__static: `"${path.join(__dirname, '../static').replace(/\\/g, '\\\\')}"`
2018-03-07 14:28:48 +01:00
})
)
}
/**
* Adjust rendererConfig for production settings
*/
if (process.env.NODE_ENV === 'production') {
rendererConfig.devtool = ''
rendererConfig.mode = 'production'
2018-03-07 14:28:48 +01:00
rendererConfig.plugins.push(
new CopyWebpackPlugin([
{
from: path.join(__dirname, '../static'),
to: path.join(__dirname, '../dist/electron/static'),
2018-07-28 13:44:16 +02:00
ignore: ['.*', '*~']
2018-03-07 14:28:48 +01:00
}
]),
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"'
}),
new webpack.LoaderOptionsPlugin({
minimize: true
})
)
}
module.exports = rendererConfig