feat: browser history is aware of basename (#45)

* feat: browser history is aware of basename

* test: fix ui options global object

* chore: fix comment
This commit is contained in:
Juan Picado @jotadeveloper 2019-05-04 12:13:29 +02:00 committed by GitHub
parent c3eac3d27b
commit a89f363115
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 1 deletions

View File

@ -3,7 +3,10 @@
*/ */
import { createBrowserHistory } from 'history'; import { createBrowserHistory } from 'history';
import { getBaseNamePath } from './utils/url';
const history = createBrowserHistory(); const history = createBrowserHistory({
basename: getBaseNamePath(),
});
export default history; export default history;

View File

@ -9,6 +9,8 @@
<link rel="icon" type="image/png" href="<%= htmlWebpackPlugin.options.verdaccioURL %>/-/static/favicon.ico" /> <link rel="icon" type="image/png" href="<%= htmlWebpackPlugin.options.verdaccioURL %>/-/static/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<script> <script>
window.__VERDACCIO_BASENAME_UI_OPTIONS = JSON.parse('<%= htmlWebpackPlugin.options.__UI_OPTIONS %>');
window.VERDACCIO_BASENAME = '<%= htmlWebpackPlugin.options.basename %>';
window.VERDACCIO_API_URL = '<%= htmlWebpackPlugin.options.verdaccioURL %>/-/verdaccio/'; window.VERDACCIO_API_URL = '<%= htmlWebpackPlugin.options.verdaccioURL %>/-/verdaccio/';
window.VERDACCIO_SCOPE = '<%= htmlWebpackPlugin.options.scope %>'; window.VERDACCIO_SCOPE = '<%= htmlWebpackPlugin.options.scope %>';
window.VERDACCIO_LOGO = '<%= htmlWebpackPlugin.options.logo %>'; window.VERDACCIO_LOGO = '<%= htmlWebpackPlugin.options.logo %>';

View File

@ -2,3 +2,11 @@ export function getRegistryURL() {
// Don't add slash if it's not a sub directory // Don't add slash if it's not a sub directory
return `${location.origin}${location.pathname === '/' ? '' : location.pathname}`; return `${location.origin}${location.pathname === '/' ? '' : location.pathname}`;
} }
export function getBaseNamePath() {
return window.__VERDACCIO_BASENAME_UI_OPTIONS.url_prefix;
}
export function getRootPath() {
return window.__VERDACCIO_BASENAME_UI_OPTIONS.base;
}

View File

@ -10,6 +10,7 @@ import Adapter from 'enzyme-adapter-react-16';
configure({ adapter: new Adapter() }); configure({ adapter: new Adapter() });
global.__APP_VERSION__ = '1.0.0'; global.__APP_VERSION__ = '1.0.0';
global.__VERDACCIO_BASENAME_UI_OPTIONS = {};
// mocking few DOM methods // mocking few DOM methods
if (global.document) { if (global.document) {

View File

@ -7,6 +7,7 @@ module.exports = {
output: { output: {
path: `${env.APP_ROOT}/static/`, path: `${env.APP_ROOT}/static/`,
filename: '[name].[hash].js', filename: '[name].[hash].js',
// FIXME: do we need this?
publicPath: 'ToReplaceByVerdaccio/-/static', publicPath: 'ToReplaceByVerdaccio/-/static',
}, },

View File

@ -45,7 +45,9 @@ const prodConf = {
}), }),
new HTMLWebpackPlugin({ new HTMLWebpackPlugin({
title: 'ToReplaceByTitle', title: 'ToReplaceByTitle',
__UI_OPTIONS: 'ToReplaceByVerdaccioUI',
scope: 'ToReplaceByScope', scope: 'ToReplaceByScope',
basename: 'ToReplaceByPrefix',
logo: 'ToReplaceByLogo', logo: 'ToReplaceByLogo',
primary_color: 'ToReplaceByPrimaryColor', primary_color: 'ToReplaceByPrimaryColor',
filename: 'index.html', filename: 'index.html',