Add HMR support

This commit is contained in:
Shawn 2019-03-05 00:24:03 -06:00
parent de3639f29c
commit 0b82953d8a
6 changed files with 96 additions and 16 deletions

View file

@ -1,9 +1,10 @@
{ {
"presets": ["@babel/react", "@babel/flow"], "presets": ["@babel/react", "@babel/flow"],
"plugins": [ "plugins": [
["@babel/plugin-proposal-decorators", { "decoratorsBeforeExport": true }], "react-hot-loader/babel",
"@babel/plugin-transform-flow-strip-types", ["@babel/plugin-proposal-decorators", { "decoratorsBeforeExport": true }],
"@babel/plugin-proposal-class-properties", "@babel/plugin-transform-flow-strip-types",
"babel-plugin-add-module-exports" "@babel/plugin-proposal-class-properties",
"babel-plugin-add-module-exports"
] ]
} }

View file

@ -1,6 +1,6 @@
{ {
"name": "LBRY", "name": "LBRY",
"version": "0.29.2", "version": "0.29.1",
"description": "A browser for the LBRY network, a digital marketplace controlled by its users.", "description": "A browser for the LBRY network, a digital marketplace controlled by its users.",
"keywords": [ "keywords": [
"lbry" "lbry"
@ -25,14 +25,16 @@
"compile": "yarn compile:electron && yarn compile:web", "compile": "yarn compile:electron && yarn compile:web",
"build": "yarn compile && electron-builder build", "build": "yarn compile && electron-builder build",
"build:dir": "yarn build -- --dir -c.compression=store -c.mac.identity=null", "build:dir": "yarn build -- --dir -c.compression=store -c.mac.identity=null",
"dev:electron": "yarn compile:electron && electron ./dist/electron/main/bundle.js", "dev:electron": "webpack-dev-server --hot --progress --config webpack.electron.config.js",
"dev:web": "webpack-dev-server --hot --progress --config webpack.web.config.js",
"dev:internal-apis": "LBRY_API_URL='http://localhost:8080' yarn dev:electron", "dev:internal-apis": "LBRY_API_URL='http://localhost:8080' yarn dev:electron",
"lint": "eslint 'src/**/*.{js,jsx}' --fix && flow", "lint": "eslint 'src/**/*.{js,jsx}' --fix && flow",
"format": "prettier 'src/**/*.{js,jsx,scss,json}' --write", "format": "prettier 'src/**/*.{js,jsx,scss,json}' --write",
"flow-defs": "flow-typed install", "flow-defs": "flow-typed install",
"precommit": "lint-staged", "precommit": "lint-staged",
"preinstall": "yarn cache clean lbry-redux && yarn cache clean lbryinc", "preinstall": "yarn cache clean lbry-redux && yarn cache clean lbryinc",
"postinstall": "electron-builder install-app-deps && node build/downloadDaemon.js" "postinstall": "electron-builder install-app-deps && node build/downloadDaemon.js",
"run:electron": "electron ./dist/electron/main/bundle.js"
}, },
"dependencies": { "dependencies": {
"@babel/polyfill": "^7.2.5", "@babel/polyfill": "^7.2.5",
@ -138,10 +140,12 @@
"node-sass": "^4.11.0", "node-sass": "^4.11.0",
"preprocess-loader": "^0.3.0", "preprocess-loader": "^0.3.0",
"prettier": "^1.11.1", "prettier": "^1.11.1",
"react-hot-loader": "^4.7.2",
"sass-loader": "^7.1.0", "sass-loader": "^7.1.0",
"style-loader": "^0.23.1", "style-loader": "^0.23.1",
"webpack": "^4.28.4", "webpack": "^4.28.4",
"webpack-build-notifier": "^0.1.23", "webpack-build-notifier": "^0.1.23",
"webpack-dev-middleware": "^3.6.0",
"webpack-dev-server": "^3.1.14", "webpack-dev-server": "^3.1.14",
"webpack-merge": "^4.2.1", "webpack-merge": "^4.2.1",
"webpack-node-externals": "^1.7.2", "webpack-node-externals": "^1.7.2",
@ -152,7 +156,7 @@
"yarn": "^1.3" "yarn": "^1.3"
}, },
"lbrySettings": { "lbrySettings": {
"lbrynetDaemonVersion": "0.32.4", "lbrynetDaemonVersion": "0.32.3",
"lbrynetDaemonUrlTemplate": "https://github.com/lbryio/lbry/releases/download/vDAEMONVER/lbrynet-OSNAME.zip", "lbrynetDaemonUrlTemplate": "https://github.com/lbryio/lbry/releases/download/vDAEMONVER/lbrynet-OSNAME.zip",
"lbrynetDaemonDir": "static", "lbrynetDaemonDir": "static",
"lbrynetDaemonFileName": "lbrynet" "lbrynetDaemonFileName": "lbrynet"

View file

@ -36,7 +36,7 @@ export default appState => {
}; };
const rendererURL = isDev // ? `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}` const rendererURL = isDev // ? `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}`
? `file://${path.resolve(__dirname, '../index.html')}` ? `http://localhost:8080/index.dev.html`
: `file://${__dirname}/index.html`; : `file://${__dirname}/index.html`;
let window = new BrowserWindow(windowConfiguration); let window = new BrowserWindow(windowConfiguration);

View file

@ -1,3 +1,4 @@
import { hot } from 'react-hot-loader/root';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { import {
selectPageTitle, selectPageTitle,
@ -29,7 +30,9 @@ const perform = dispatch => ({
toggleEnhancedLayout: () => dispatch(doToggleEnhancedLayout()), toggleEnhancedLayout: () => dispatch(doToggleEnhancedLayout()),
}); });
export default connect( export default hot(
select, connect(
perform select,
)(App); perform
)(App)
);

15
static/index.dev.html Normal file
View file

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script>
require('source-map-support/source-map-support.js').install();
</script>
</head>
<body>
<div id="app"></div>
<script type="text/javascript" src="http://localhost:8080/ui/bundle.js"></script>
</body>
</html>

View file

@ -6,10 +6,64 @@ const CopyWebpackPlugin = require('copy-webpack-plugin');
const STATIC_ROOT = path.resolve(__dirname, 'static/'); const STATIC_ROOT = path.resolve(__dirname, 'static/');
const DIST_ROOT = path.resolve(__dirname, 'dist/'); const DIST_ROOT = path.resolve(__dirname, 'dist/');
const electronConfig = {
target: 'electron-renderer', const mainConfig = {
target: 'electron-main',
entry: { entry: {
main: './src/platforms/electron/index.js', main: './src/platforms/electron/index.js',
},
output: {
filename: '[name]/bundle.js',
path: __dirname + '/dist/electron',
},
module: {
rules: [
{
test: /\.node$/,
use: 'node-loader',
},
{
test: /\.jsx?$/,
use: [
{
loader: 'preprocess-loader',
options: {
TARGET: 'app',
ppOptions: {
type: 'js',
},
},
},
],
},
],
},
resolve: {
alias: {
// 'src/electron': path.resolve(__dirname, 'src/platforms/electron');
}
},
plugins: [
new CopyWebpackPlugin([
{
from: `${STATIC_ROOT}/`,
to: `${DIST_ROOT}/electron/static/`,
ignore: ['font/**/*', 'index.html'],
},
{
from: `${STATIC_ROOT}/index.html`,
to: `${DIST_ROOT}/electron/index.html`,
},
]),
],
devServer: {
contentBase: path.join(__dirname, 'dist/electron')
},
};
const renderConfig = {
target: 'electron-renderer',
entry: {
ui: './src/ui/index.js', ui: './src/ui/index.js',
}, },
output: { output: {
@ -58,4 +112,7 @@ const electronConfig = {
], ],
}; };
module.exports = merge(baseConfig, electronConfig); module.exports = [
merge(baseConfig, mainConfig),
merge(baseConfig, renderConfig),
];