mirror of
https://github.com/frappe/books.git
synced 2024-11-10 07:40:55 +00:00
Separate config for electron main
This commit is contained in:
parent
af5c34c6fd
commit
82f769dcfe
@ -1,19 +1,30 @@
|
||||
const webpack = require('webpack');
|
||||
const getWebpackConfig = require('./config');
|
||||
const { getConfig, getElectronMainConfig } = require('./config');
|
||||
|
||||
module.exports = function build(mode) {
|
||||
const webpackConfig = getWebpackConfig();
|
||||
const rendererConfig = getConfig();
|
||||
const mainConfig = getElectronMainConfig();
|
||||
|
||||
process.env.NODE_ENV = 'production';
|
||||
|
||||
if (mode === 'electron') {
|
||||
pack(webpackConfig)
|
||||
pack(rendererConfig)
|
||||
.then(result => {
|
||||
console.log(result);
|
||||
}).catch(err => {
|
||||
console.log(`\n Failed to build renderer process`);
|
||||
console.error(`\n${err}\n`);
|
||||
process.exit(1)
|
||||
})
|
||||
});
|
||||
|
||||
pack(mainConfig)
|
||||
.then(result => {
|
||||
console.log(result);
|
||||
}).catch(err => {
|
||||
console.log(`\n Failed to build main process`);
|
||||
console.error(`\n${err}\n`);
|
||||
process.exit(1)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,21 +1,19 @@
|
||||
const webpack = require('webpack');
|
||||
|
||||
// plugins
|
||||
const VueLoaderPlugin = require('vue-loader/lib/plugin');
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
const CaseSensitivePathsWebpackPlugin = require('case-sensitive-paths-webpack-plugin');
|
||||
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
|
||||
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
||||
|
||||
const { getAppConfig, resolveAppDir } = require('./utils');
|
||||
const appDependencies = require(resolveAppDir('./package.json')).dependencies;
|
||||
const frappeDependencies = require('../package.json').dependencies;
|
||||
|
||||
function getConfig() {
|
||||
const plugins = {
|
||||
NamedModules: webpack.NamedModulesPlugin,
|
||||
HotModuleReplacement: webpack.HotModuleReplacementPlugin,
|
||||
Define: webpack.DefinePlugin,
|
||||
Progress: webpack.ProgressPlugin,
|
||||
VueLoader: require('vue-loader/lib/plugin'),
|
||||
Html: require('html-webpack-plugin'),
|
||||
CaseSensitivePaths: require('case-sensitive-paths-webpack-plugin'),
|
||||
FriendlyErrors: require('friendly-errors-webpack-plugin'),
|
||||
CopyWebpackPlugin: require('copy-webpack-plugin')
|
||||
}
|
||||
let getConfig, getElectronMainConfig;
|
||||
|
||||
function makeConfig() {
|
||||
const appConfig = getAppConfig();
|
||||
const isProduction = process.env.NODE_ENV === 'production';
|
||||
const isElectron = process.env.ELECTRON === 'true';
|
||||
@ -23,8 +21,9 @@ function getConfig() {
|
||||
|
||||
const whiteListedModules = ['vue'];
|
||||
const allDependencies = Object.assign(frappeDependencies, appDependencies);
|
||||
const externals = Object.keys(allDependencies).filter(d => !whiteListedModules.includes(d))
|
||||
const externals = Object.keys(allDependencies).filter(d => !whiteListedModules.includes(d));
|
||||
|
||||
getConfig = function getConfig() {
|
||||
const config = {
|
||||
mode: isProduction ? 'production' : 'development',
|
||||
context: resolveAppDir(),
|
||||
@ -88,29 +87,29 @@ function getConfig() {
|
||||
}
|
||||
},
|
||||
plugins: [
|
||||
new plugins.Define(Object.assign({
|
||||
new webpack.DefinePlugin(Object.assign({
|
||||
'process.env': appConfig.dev.env,
|
||||
'process.env.NODE_ENV': isProduction ? '"production"' : '"development"',
|
||||
}, !isProduction ? {
|
||||
'__static': `"${resolveAppDir(appConfig.staticPath).replace(/\\/g, '\\\\')}"`
|
||||
} : {})),
|
||||
new plugins.VueLoader(),
|
||||
new plugins.Html({
|
||||
new VueLoaderPlugin(),
|
||||
new HtmlWebpackPlugin({
|
||||
template: resolveAppDir(appConfig.dev.entryHtml),
|
||||
nodeModules: !isProduction
|
||||
? isMonoRepo ? resolveAppDir('../../node_modules') : resolveAppDir('./node_modules')
|
||||
: false
|
||||
}),
|
||||
new plugins.CaseSensitivePaths(),
|
||||
new plugins.NamedModules(),
|
||||
new plugins.HotModuleReplacement(),
|
||||
new plugins.FriendlyErrors({
|
||||
new CaseSensitivePathsWebpackPlugin(),
|
||||
new webpack.NamedModulesPlugin(),
|
||||
new webpack.HotModuleReplacementPlugin(),
|
||||
new FriendlyErrorsWebpackPlugin({
|
||||
compilationSuccessInfo: {
|
||||
messages: [`FrappeJS server started at http://${appConfig.dev.devServerHost}:${appConfig.dev.devServerPort}`],
|
||||
},
|
||||
}),
|
||||
new plugins.Progress(),
|
||||
isProduction ? new plugins.CopyWebpackPlugin([
|
||||
new webpack.ProgressPlugin(),
|
||||
isProduction ? new CopyWebpackPlugin([
|
||||
{
|
||||
from: resolveAppDir(appConfig.staticPath),
|
||||
to: resolveAppDir('./dist/electron/static'),
|
||||
@ -150,6 +149,54 @@ function getConfig() {
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
getElectronMainConfig = function getElectronMainConfig() {
|
||||
return {
|
||||
entry: {
|
||||
main: resolveAppDir(appConfig.electron.paths.main)
|
||||
},
|
||||
externals: externals,
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.js$/,
|
||||
use: 'babel-loader',
|
||||
exclude: /node_modules/
|
||||
},
|
||||
{
|
||||
test: /\.node$/,
|
||||
use: 'node-loader'
|
||||
}
|
||||
]
|
||||
},
|
||||
node: {
|
||||
__dirname: !isProduction,
|
||||
__filename: !isProduction
|
||||
},
|
||||
output: {
|
||||
filename: '[name].js',
|
||||
libraryTarget: 'commonjs2',
|
||||
path: resolveAppDir('./dist/electron')
|
||||
},
|
||||
plugins: [
|
||||
new webpack.NoEmitOnErrorsPlugin(),
|
||||
// isProduction && new BabiliWebpackPlugin(),
|
||||
isProduction && new webpack.DefinePlugin({
|
||||
'process.env.NODE_ENV': '"production"'
|
||||
})
|
||||
],
|
||||
resolve: {
|
||||
extensions: ['.js', '.json', '.node']
|
||||
},
|
||||
target: 'electron-main'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = getConfig;
|
||||
makeConfig();
|
||||
|
||||
module.exports = {
|
||||
getConfig,
|
||||
getElectronMainConfig
|
||||
};
|
||||
|
@ -5,7 +5,7 @@ const webpackHotMiddleware = require('webpack-hot-middleware');
|
||||
|
||||
const logger = require('./logger');
|
||||
const { getAppConfig, resolveAppDir } = require('./utils');
|
||||
const getWebpackConfig = require('./config');
|
||||
const { getConfig: getWebpackConfig } = require('./config');
|
||||
|
||||
const log = logger('serve');
|
||||
const warn = logger('serve', 'red');
|
||||
|
Loading…
Reference in New Issue
Block a user