forked from LN-Zap/zap-desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: consolidate webpack configs
- Loading branch information
Showing
21 changed files
with
1,303 additions
and
2,567 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { spawn } from 'child_process' | ||
import { mainLog } from '@zap/utils/log' | ||
|
||
export const port = process.env.PORT || 1212 | ||
export const publicPath = `http://localhost:${port}/dist` | ||
|
||
const devServer = { | ||
port, | ||
hot: true, | ||
publicPath, | ||
headers: { 'Access-Control-Allow-Origin': '*' }, | ||
writeToDisk: true, | ||
|
||
watchOptions: { | ||
aggregateTimeout: 300, | ||
ignored: /node_modules/, | ||
poll: 100, | ||
}, | ||
|
||
proxy: { | ||
'/proxy/zap.jackmallers.com': { | ||
target: 'https://zap.jackmallers.com', | ||
pathRewrite: { '^/proxy/zap.jackmallers.com': '' }, | ||
changeOrigin: true, | ||
}, | ||
'/proxy/api.coinbase.com': { | ||
target: 'https://api.coinbase.com', | ||
pathRewrite: { '^/proxy/api.coinbase.com': '' }, | ||
changeOrigin: true, | ||
}, | ||
'/proxy/tchain.api.btc.com': { | ||
target: 'https://tchain.api.btc.com', | ||
pathRewrite: { '^/proxy/tchain.api.btc.com': '' }, | ||
changeOrigin: true, | ||
}, | ||
}, | ||
|
||
historyApiFallback: true, | ||
|
||
// Start the main process as soon as the server is listening. | ||
after: () => { | ||
if (process.env.HOT) { | ||
spawn('npm', ['run', 'start-main-dev'], { | ||
shell: true, | ||
env: process.env, | ||
stdio: 'inherit', | ||
}) | ||
.on('close', code => process.exit(code)) | ||
.on('error', spawnError => mainLog.error(spawnError)) | ||
} | ||
}, | ||
} | ||
|
||
export default devServer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import webpack from 'webpack' | ||
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer' | ||
|
||
const plugins = [ | ||
new webpack.EnvironmentPlugin({ | ||
NODE_ENV: 'development', | ||
}), | ||
new BundleAnalyzerPlugin({ | ||
analyzerMode: process.env.OPEN_ANALYZER === 'true' ? 'server' : 'disabled', | ||
openAnalyzer: process.env.OPEN_ANALYZER === 'true', | ||
}), | ||
] | ||
|
||
export default plugins |
33 changes: 13 additions & 20 deletions
33
webpack/webpack.config.preload.dev.js → webpack/dev/main.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,40 @@ | ||
/** | ||
* Webpack config for development electron preload process | ||
* Webpack config for production electron main process | ||
*/ | ||
|
||
import path from 'path' | ||
import merge from 'webpack-merge' | ||
import { EnvironmentPlugin } from 'webpack' | ||
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer' | ||
import baseConfig, { rootDir } from './webpack.config.base' | ||
|
||
export default merge.smart(baseConfig, { | ||
devtool: 'source-map', | ||
|
||
target: 'electron-renderer', | ||
import baseConfig, { rootDir } from '../webpack.config.base' | ||
import devServer, { publicPath } from './common/devserver' | ||
|
||
const config = merge.smart(baseConfig, { | ||
name: 'main', | ||
target: 'electron-main', | ||
mode: 'development', | ||
|
||
devtool: 'source-map', | ||
entry: { | ||
preload: path.join(rootDir, 'electron', 'preload'), | ||
main: path.join(rootDir, 'electron', 'main'), | ||
}, | ||
|
||
output: { | ||
path: path.join(rootDir, 'dist'), | ||
filename: '[name].dev.js', | ||
filename: '[name].js', | ||
publicPath, | ||
}, | ||
|
||
devServer, | ||
plugins: [ | ||
new EnvironmentPlugin({ | ||
NODE_ENV: 'development', | ||
}), | ||
|
||
new BundleAnalyzerPlugin({ | ||
analyzerMode: process.env.OPEN_ANALYZER === 'true' ? 'server' : 'disabled', | ||
openAnalyzer: process.env.OPEN_ANALYZER === 'true', | ||
}), | ||
], | ||
|
||
/** | ||
* Disables webpack processing of __dirname and __filename. | ||
* If you run the bundle in node.js it falls back to these values of node.js. | ||
* https://github.com/webpack/webpack/issues/2010 | ||
*/ | ||
node: { | ||
__dirname: false, | ||
__filename: false, | ||
}, | ||
}) | ||
|
||
export default config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import path from 'path' | ||
import merge from 'webpack-merge' | ||
import baseConfig, { rootDir } from '../webpack.config.base' | ||
import devServer, { publicPath } from './common/devserver' | ||
import plugins from './common/plugins' | ||
|
||
const config = merge.smart(baseConfig, { | ||
name: 'preload', | ||
target: 'electron-renderer', | ||
mode: 'development', | ||
devtool: 'source-map', | ||
entry: { | ||
preload: path.join(rootDir, 'electron', 'preload'), | ||
}, | ||
output: { | ||
filename: '[name].js', | ||
publicPath, | ||
}, | ||
devServer, | ||
plugins, | ||
node: { | ||
__dirname: false, | ||
__filename: false, | ||
}, | ||
}) | ||
|
||
export default config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* eslint global-require: 0, import/no-dynamic-require: 0 */ | ||
import path from 'path' | ||
import webpack from 'webpack' | ||
import merge from 'webpack-merge' | ||
import AddAssetHtmlPlugin from 'add-asset-html-webpack-plugin' | ||
import CopyWebpackPlugin from 'copy-webpack-plugin' | ||
import HtmlWebpackPlugin from 'html-webpack-plugin' | ||
import CspHtmlWebpackPlugin from 'csp-html-webpack-plugin' | ||
import baseConfig, { rootDir } from '../webpack.config.base' | ||
import devServer, { publicPath } from './common/devserver' | ||
import plugins from './common/plugins' | ||
|
||
const dll = path.resolve(rootDir, 'dll') | ||
const manifest = path.resolve(dll, 'renderer.json') | ||
|
||
const config = merge.smart(baseConfig, { | ||
name: 'renderer', | ||
target: 'web', | ||
mode: 'development', | ||
devtool: 'inline-source-map', | ||
entry: { | ||
renderer: path.join(rootDir, 'renderer', 'index'), | ||
}, | ||
output: { | ||
filename: '[name].js', | ||
publicPath, | ||
}, | ||
stats: { | ||
children: false, | ||
}, | ||
devServer, | ||
plugins: [ | ||
...plugins, | ||
new HtmlWebpackPlugin({ | ||
inject: true, | ||
template: path.join('renderer', 'app.html'), | ||
}), | ||
new CspHtmlWebpackPlugin({ | ||
'default-src': "'self'", | ||
'object-src': "'none'", | ||
'connect-src': [ | ||
"'self'", | ||
'http://localhost:*', | ||
'ws://localhost:*', | ||
'https://api.coinbase.com/', | ||
'https://testnet-api.smartbit.com.au', | ||
'https://tchain.api.btc.com', | ||
'https://api.blockcypher.com', | ||
'https://bitcoinfees.earn.com', | ||
'https://zap.jackmallers.com', | ||
], | ||
'img-src': ['http://www.zap.jackmallers.com'], | ||
'script-src': ["'self'", 'http://localhost:*', "'unsafe-eval'"], | ||
'font-src': [ | ||
"'self'", | ||
'data:', | ||
'http://localhost:*', | ||
'https://s3.amazonaws.com', | ||
'https://fonts.gstatic.com', | ||
], | ||
'style-src': ["'self'", 'blob:', 'https://s3.amazonaws.com', "'unsafe-inline'"], | ||
}), | ||
new webpack.DllReferencePlugin({ | ||
context: process.cwd(), | ||
manifest: require(manifest), | ||
sourceType: 'var', | ||
}), | ||
new AddAssetHtmlPlugin({ | ||
filepath: path.join('dll', 'renderer.dll.js'), | ||
includeSourcemap: true, | ||
}), | ||
new CopyWebpackPlugin([ | ||
path.join('renderer', 'empty.html'), | ||
{ from: path.join('electron', 'about'), to: 'about' }, | ||
]), | ||
], | ||
node: { | ||
fs: 'empty', | ||
module: 'empty', | ||
}, | ||
optimization: { | ||
noEmitOnErrors: true, | ||
}, | ||
}) | ||
|
||
export default config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import webpack from 'webpack' | ||
|
||
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer' | ||
|
||
const plugins = [ | ||
new webpack.EnvironmentPlugin({ | ||
NODE_ENV: 'production', | ||
}), | ||
new BundleAnalyzerPlugin({ | ||
analyzerMode: process.env.OPEN_ANALYZER === 'true' ? 'server' : 'disabled', | ||
openAnalyzer: process.env.OPEN_ANALYZER === 'true', | ||
}), | ||
] | ||
|
||
export default plugins |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import path from 'path' | ||
import merge from 'webpack-merge' | ||
import baseConfig, { rootDir } from '../webpack.config.base' | ||
import plugins from './common/plugins' | ||
|
||
const config = merge.smart(baseConfig, { | ||
name: 'preload', | ||
target: 'electron-renderer', | ||
mode: 'production', | ||
devtool: 'source-map', | ||
entry: { | ||
preload: path.join(rootDir, 'electron', 'preload'), | ||
}, | ||
output: { | ||
filename: '[name].js', | ||
path: path.join(rootDir, 'dist'), | ||
}, | ||
plugins, | ||
node: { | ||
__dirname: false, | ||
__filename: false, | ||
}, | ||
}) | ||
|
||
export default config |
Oops, something went wrong.