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 CopyWebpackPlugin = require('copy-webpack-plugin')
|
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
|
|
|
|
|
|
|
const {
|
|
|
|
dependencies,
|
|
|
|
devDependencies,
|
|
|
|
productName,
|
|
|
|
} = require('../package.json')
|
|
|
|
|
|
|
|
const externals = Object.keys(dependencies).concat(Object.keys(devDependencies))
|
|
|
|
const isDevMode = process.env.NODE_ENV === 'development'
|
|
|
|
const whiteListedModules = ['vue']
|
|
|
|
|
|
|
|
const config = {
|
|
|
|
name: 'renderer',
|
|
|
|
mode: process.env.NODE_ENV,
|
2020-03-24 13:22:29 +00:00
|
|
|
devtool: isDevMode ? '#cheap-module-eval-source-map' : false,
|
2020-02-16 18:30:00 +00:00
|
|
|
entry: {
|
|
|
|
renderer: path.join(__dirname, '../src/renderer/main.js'),
|
|
|
|
},
|
|
|
|
output: {
|
|
|
|
libraryTarget: 'commonjs2',
|
|
|
|
path: path.join(__dirname, '../dist'),
|
|
|
|
filename: '[name].js',
|
|
|
|
},
|
|
|
|
externals: externals.filter(d => !whiteListedModules.includes(d)),
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.(j|t)s$/,
|
|
|
|
use: 'babel-loader',
|
|
|
|
exclude: /node_modules/,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.node$/,
|
|
|
|
use: 'node-loader',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.vue$/,
|
|
|
|
loader: 'vue-loader',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.s(c|a)ss$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: MiniCssExtractPlugin.loader,
|
|
|
|
options: {
|
|
|
|
hmr: isDevMode,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'sass-loader',
|
|
|
|
options: {
|
|
|
|
// eslint-disable-next-line
|
|
|
|
implementation: require('sass'),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: MiniCssExtractPlugin.loader,
|
|
|
|
options: {
|
|
|
|
hmr: isDevMode,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'css-loader',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(png|jpe?g|gif|tif?f|bmp|webp|svg)(\?.*)?$/,
|
|
|
|
use: {
|
|
|
|
loader: 'url-loader',
|
2020-03-24 13:22:29 +00:00
|
|
|
options: {
|
|
|
|
esModule: false,
|
2020-02-16 18:30:00 +00:00
|
|
|
limit: 10000,
|
|
|
|
name: 'imgs/[name]--[folder].[ext]',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
|
|
|
|
use: {
|
|
|
|
loader: 'url-loader',
|
2020-03-24 13:22:29 +00:00
|
|
|
options: {
|
|
|
|
esModule: false,
|
2020-02-16 18:30:00 +00:00
|
|
|
limit: 10000,
|
|
|
|
name: 'fonts/[name]--[folder].[ext]',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
node: {
|
|
|
|
__dirname: isDevMode,
|
|
|
|
__filename: isDevMode,
|
|
|
|
},
|
|
|
|
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({
|
|
|
|
filename: '[name].css',
|
|
|
|
chunkFilename: '[id].css',
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
vue$: 'vue/dist/vue.common.js',
|
|
|
|
'@': path.join(__dirname, '../src/'),
|
|
|
|
src: path.join(__dirname, '../src/'),
|
|
|
|
icons: path.join(__dirname, '../_icons/'),
|
|
|
|
},
|
|
|
|
extensions: ['.ts', '.js', '.vue', '.json'],
|
|
|
|
},
|
|
|
|
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.HotModuleReplacementPlugin(),
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
__static: `"${path.join(__dirname, '../static').replace(/\\/g, '\\\\')}"`,
|
|
|
|
})
|
|
|
|
)
|
2020-02-16 18:30:00 +00:00
|
|
|
} else {
|
|
|
|
config.plugins.push(
|
|
|
|
new CopyWebpackPlugin([
|
|
|
|
{
|
|
|
|
from: path.join(__dirname, '../static'),
|
|
|
|
to: path.join(__dirname, '../dist/static'),
|
2020-03-24 13:22:29 +00:00
|
|
|
ignore: ['.*'],
|
2020-02-16 18:30:00 +00:00
|
|
|
},
|
2020-03-24 13:22:29 +00:00
|
|
|
]),
|
|
|
|
new webpack.LoaderOptionsPlugin({
|
|
|
|
minimize: true,
|
|
|
|
})
|
2020-02-16 18:30:00 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = config
|