Skip to content
Snippets Groups Projects
Commit 35d8459b authored by Chris Beer's avatar Chris Beer
Browse files

Use webpack-dev-server and HMR for development

parent 83246df5
Branches
No related tags found
No related merge requests found
......@@ -20,7 +20,7 @@ Mirador local development requires [nodejs](https://nodejs.org/en/download/) to
$ npm start
```
Then navigate to [http://127.0.0.1:4444/\_\_tests\_\_/integration/mirador/](http://127.0.0.1:4444/\_\_tests\_\_/integration/mirador/)
Then navigate to [http://127.0.0.1:4444/](http://127.0.0.1:4444/)
### Instantiating Mirador
......
......@@ -84,7 +84,9 @@ module.exports = function (api) {
'lodash',
],
},
]];
],
'react-hot-loader/babel',
];
return {
plugins,
......
......@@ -22,7 +22,7 @@
"build:watch": "webpack --watch --mode=development",
"prepublishOnly": "npm run clean && npm run build:es && npm run build:cjs && npm run build",
"size": "bundlewatch --config bundlewatch.config.json",
"start": "npm run build:dev && concurrently -k \"npm:build:watch\" \"npm:server -- -p 4444\""
"start": "webpack-dev-server --open"
},
"license": "Apache-2.0",
"contributors": [
......@@ -56,6 +56,7 @@
"react-beautiful-dnd": "^11.0.4",
"react-copy-to-clipboard": "^5.0.1",
"react-full-screen": "^0.2.4",
"react-hot-loader": "^4.12.21",
"react-i18next": "^10.11.4",
"react-image": "^2.1.3",
"react-mosaic-component": "^4.0.1",
......@@ -120,7 +121,8 @@
"unfetch": "^4.1.0",
"url-polyfill": "^1.1.7",
"webpack": "^4.35.3",
"webpack-cli": "^3.3.5"
"webpack-cli": "^3.3.5",
"webpack-dev-server": "^3.11.0"
},
"peerDependencies": {
"react": "^16.8.3",
......
import React, { Component, lazy, Suspense } from 'react';
import { hot } from 'react-hot-loader/root';
import PropTypes from 'prop-types';
import PluginProvider from '../extend/PluginProvider';
import createRootReducer from '../state/reducers/rootReducer';
......@@ -43,3 +44,5 @@ App.propTypes = {
App.defaultProps = {
plugins: [],
};
export default hot(App);
......@@ -2,7 +2,7 @@ import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { v4 as uuid } from 'uuid';
import { App } from '../components/App';
import HotApp from '../components/App';
import createStore from '../state/createStore';
import * as actions from '../state/actions';
import { getCompanionWindowIdsForPosition, getManifestSearchService } from '../state/selectors';
......@@ -26,7 +26,7 @@ class MiradorViewer {
ReactDOM.render(
<Provider store={this.store}>
<App plugins={this.plugins} />
<HotApp plugins={this.plugins} />
</Provider>,
document.getElementById(config.id),
);
......
......@@ -3,7 +3,11 @@ const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
const paths = require('./config/paths');
const babelLoaderConfig = {
const baseConfig = {
entry: ['react-hot-loader/patch', './src/polyfills.js', './src/index.js'],
module: {
rules: [
{
include: paths.appPath, // CRL
loader: require.resolve('babel-loader'),
options: {
......@@ -13,13 +17,7 @@ const babelLoaderConfig = {
compact: true,
},
test: /\.(js|mjs|jsx)$/,
};
const baseConfig = [
{
entry: ['./src/polyfills.js', './src/index.js'],
module: {
rules: [
babelLoaderConfig,
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
......@@ -47,19 +45,31 @@ const baseConfig = [
}),
],
resolve: { extensions: ['.js'] },
},
];
};
module.exports = (env, options) => {
const isProduction = options.mode === 'production';
return baseConfig.map((config) => {
if (isProduction) {
config.plugins.push(new webpack.optimize.LimitChunkCountPlugin({
return {
...baseConfig,
plugins: [
...(baseConfig.plugins || []),
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1,
}));
} else {
config.devtool = 'eval-source-map'; // eslint-disable-line no-param-reassign
}),
],
};
}
return config;
});
return {
...baseConfig,
devServer: {
contentBase: './__tests__/integration/mirador',
hot: true,
port: 4444,
},
devtool: 'eval-source-map',
mode: 'development',
};
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment