67 lines
1.7 KiB
JavaScript
Raw Normal View History

2017-01-17 13:40:59 +01:00
/**
* app.js
*
* This is the entry file for the application,
* only setup and plugin code.
*/
2017-03-18 17:34:00 +01:00
import { Provider } from 'react-redux';
import App, { bootstrap } from 'containers/App'; // eslint-disable-line
import configureStore from './store';
import { translationMessages } from './i18n';
2017-01-17 13:40:59 +01:00
2017-05-11 15:52:22 +02:00
// Plugin identifier based on the package.json `name` value
const pluginPkg = require('../../../../package.json');
const pluginId = pluginPkg.name.replace(
2017-05-11 15:52:22 +02:00
/^strapi-plugin-/i,
''
);
2017-06-08 17:16:20 +01:00
const pluginName = pluginPkg.strapi.name;
const pluginDescription = pluginPkg.strapi.description || pluginPkg.description;
2017-05-11 15:52:22 +02:00
const apiUrl = window.Strapi && `${window.Strapi.apiUrl}/${pluginId}`;
const router = window.Strapi.router;
// Create redux store with Strapi admin history
2017-05-10 11:41:53 +02:00
const store = configureStore({}, window.Strapi.router);
2017-05-11 15:52:22 +02:00
// Define the plugin root component
function Comp(props) {
return (
<Provider store={store}>
<App {...props} />
</Provider>
);
2017-03-18 17:34:00 +01:00
}
// Hot reloadable translation json files
if (module.hot) {
// modules.hot.accept does not accept dynamic dependencies,
// have to be constants at compile-time
module.hot.accept('./i18n', () => {
if (window.Strapi) {
System.import('./i18n').then(result => {
const translationMessagesUpdated = result.translationMessages;
window.Strapi
.refresh(pluginId)
.translationMessages(translationMessagesUpdated);
});
}
});
}
// Register the plugin.
window.Strapi.registerPlugin({
name: pluginPkg.strapi.name,
icon: pluginPkg.strapi.icon,
id: pluginId,
leftMenuLinks: [],
mainComponent: Comp,
translationMessages,
bootstrap,
});
2017-01-17 13:40:59 +01:00
// Export store
2017-06-08 17:16:20 +01:00
export { store, apiUrl, pluginId, pluginName, pluginDescription, router };