up bootstrap

This commit is contained in:
Andrey Vlasov 2020-02-29 16:47:16 +03:00
parent 3e2695801d
commit 88a38bc75e
19 changed files with 300 additions and 1614 deletions

1105
dist/bootstrap.js vendored

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

240
dist/index.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,161 +0,0 @@
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("react"), require("react-dom"));
else if(typeof define === 'function' && define.amd)
define(["react", "react-dom"], factory);
else {
var a = typeof exports === 'object' ? factory(require("react"), require("react-dom")) : factory(root["react"], root["react-dom"]);
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
}
})((typeof self !== 'undefined' ? self : this), function(__WEBPACK_EXTERNAL_MODULE_react__, __WEBPACK_EXTERNAL_MODULE_react_dom__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 1);
/******/ })
/************************************************************************/
/******/ ({
/***/ "./src/example/main.tsx":
/*!******************************!*\
!*** ./src/example/main.tsx ***!
\******************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importDefault(__webpack_require__(/*! react */ "react"));
var react_dom_1 = __importDefault(__webpack_require__(/*! react-dom */ "react-dom"));
exports.default = (function () { return (react_1.default.createElement("div", null, "\u041D\u0430\u0448\u0435 \u043F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u04351")); });
exports.mount = function (component) {
react_dom_1.default.render(component, document.getElementById('app'));
};
exports.unmount = function () {
react_dom_1.default.unmountComponentAtNode(document.getElementById('app'));
};
/***/ }),
/***/ 1:
/*!************************************!*\
!*** multi ./src/example/main.tsx ***!
\************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(/*! ./src/example/main.tsx */"./src/example/main.tsx");
/***/ }),
/***/ "react":
/*!************************!*\
!*** external "react" ***!
\************************/
/*! no static exports found */
/***/ (function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_react__;
/***/ }),
/***/ "react-dom":
/*!****************************!*\
!*** external "react-dom" ***!
\****************************/
/*! no static exports found */
/***/ (function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_react_dom__;
/***/ })
/******/ });
});
//# sourceMappingURL=example.js.map

File diff suppressed because one or more lines are too long

View File

@ -1,161 +0,0 @@
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("react"), require("react-dom"));
else if(typeof define === 'function' && define.amd)
define(["react", "react-dom"], factory);
else {
var a = typeof exports === 'object' ? factory(require("react"), require("react-dom")) : factory(root["react"], root["react-dom"]);
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
}
})((typeof self !== 'undefined' ? self : this), function(__WEBPACK_EXTERNAL_MODULE_react__, __WEBPACK_EXTERNAL_MODULE_react_dom__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 2);
/******/ })
/************************************************************************/
/******/ ({
/***/ "./src/example2/main.tsx":
/*!*******************************!*\
!*** ./src/example2/main.tsx ***!
\*******************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importDefault(__webpack_require__(/*! react */ "react"));
var react_dom_1 = __importDefault(__webpack_require__(/*! react-dom */ "react-dom"));
exports.default = (function () { return (react_1.default.createElement("div", null, "\u041D\u0430\u0448\u0435 \u043F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u04352")); });
exports.mount = function (component) {
react_dom_1.default.render(component, document.getElementById('app'));
};
exports.unmount = function () {
react_dom_1.default.unmountComponentAtNode(document.getElementById('app'));
};
/***/ }),
/***/ 2:
/*!*************************************!*\
!*** multi ./src/example2/main.tsx ***!
\*************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(/*! ./src/example2/main.tsx */"./src/example2/main.tsx");
/***/ }),
/***/ "react":
/*!************************!*\
!*** external "react" ***!
\************************/
/*! no static exports found */
/***/ (function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_react__;
/***/ }),
/***/ "react-dom":
/*!****************************!*\
!*** external "react-dom" ***!
\****************************/
/*! no static exports found */
/***/ (function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_react_dom__;
/***/ })
/******/ });
});
//# sourceMappingURL=example2.js.map

File diff suppressed because one or more lines are too long

View File

@ -31,8 +31,8 @@
"systemjs": "6.2.2",
"typescript": "3.7.5",
"uds-news-original": "0.1.1",
"uds-sections-origin": "1.0.1",
"uds-org": "../uds-org",
"uds-sections-origin": "1.0.1",
"webpack": "4.41.5",
"webpack-cli": "3.3.10",
"webpack-dev-middleware": "3.7.2",

BIN
src/.DS_Store vendored

Binary file not shown.

View File

@ -1,23 +0,0 @@
import React from 'react';
import ReactDom from 'react-dom';
export default () => (<div>Наше приложение1</div>);
export const mount = (Сomponent) => {
// console.log('component', component);
ReactDom.render(
<Сomponent/>,
document.getElementById('app')
);
}
export const unmount = () => {
ReactDom.unmountComponentAtNode(document.getElementById('app'))
}

View File

@ -1,20 +0,0 @@
import React from 'react';
import ReactDom from 'react-dom';
export default () => (<div>Наше приложение2</div>);
export const mount = (Сomponent) => {
ReactDom.render(
<Сomponent/>,
document.getElementById('app')
);
}
export const unmount = () => {
ReactDom.unmountComponentAtNode(document.getElementById('app'))
}

View File

@ -1,7 +0,0 @@
const sysytemJs = require("systemjs/dist/system");
module.export = ({ apps, navigations, config }) => {
console.log("apps", apps);
sysytemJs.import("./main/index.js");
};

46
src/main.ts Normal file
View File

@ -0,0 +1,46 @@
import "systemjs/dist/s";
import "systemjs/dist/extras/amd";
import "systemjs/dist/extras/named-register";
import "systemjs/dist/extras/named-exports";
import "systemjs/dist/extras/transform";
import { createBrowserHistory } from 'history'
declare var System: {
import(string): Promise<any>
}
const systemJSImport = async (requestUrl: string) => {
const { default: component, mount, unmount } = await System.import(
requestUrl
)
return { component, mount, unmount }
}
const getApp = (apps, path) => {
const searchKey = path.substr(1)
return `./${searchKey}/${apps[searchKey].version}/index.js`
}
export default async ({ apps, navigations, config }) => {
const history = createBrowserHistory()
let prevPathname = window.location.pathname
/* tslint:disable-next-line */
__webpack_public_path__ = `/static${__webpack_public_path__}`
const app = getApp(apps, history.location.pathname)
const { component, mount, unmount } = await systemJSImport(app);
mount(component.default);
history.listen((location) => {
if (location.pathname !== prevPathname) {
prevPathname = location.pathname
unmount()
}
})
};

View File

@ -1,50 +0,0 @@
import React from 'react';
import ReactDom from 'react-dom';
import { loadApp } from './utils';
class Bootstrap extends React.PureComponent <any, any> {
App: any;
currentBundle: string = '';
async downloader(bundleName: string) {
let _bundleName = bundleName;
this.currentBundle = bundleName;
this.App = await loadApp(_bundleName);
this.forceUpdate();
}
mountApp = async(nameApp) => {
await this.downloader(nameApp);
this.App.mount(this.App.default)
}
unmountApp = () => {
this.App.unmount();
}
render () {
return (
<div>
<button onClick={() => this.mountApp('pl')}>
загрузить приложение news
</button>
<button onClick={() => this.mountApp('uds-sections')}>
загрузить приложение uds-sections
</button>
<button onClick={() => this.mountApp('orgApp')}>
загрузить приложение org
</button>
<button onClick={() => this.unmountApp()}>
выгрузить приложение 2
</button>
</div>
);
}
}
ReactDom.render(
<Bootstrap/>,
document.getElementById('bootstrap')
);

View File

@ -1,10 +0,0 @@
export async function loadApp(bundleName) {
return await System.import(`./${bundleName}.js`)
.then(result => {
return result.default;
})
.catch(error => {
console.info(`Загрузить ${bundleName} не удалось!`);
console.info(`error in ${bundleName}`, error);
});
}

View File

@ -1,26 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link
href="https://fonts.googleapis.com/css?family=Montserrat:400,600,700,900&amp;subset=cyrillic,cyrillic-ext"
rel="stylesheet"
/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Занятие по загрузчику</title>
<script type="systemjs-importmap" src="/importmap.json"></script>
<script src="extlib/systemjs/system.js"></script>
<script src="extlib/systemjs/extras/amd.js"></script>
<script src="extlib/systemjs/extras/named-register.js"></script>
<script src="extlib/systemjs/extras/named-exports.js"></script>
<script src="extlib/systemjs/extras/transform.js"></script>
</head>
<body>
<script type="text/javascript">
System.import('./bootstrap.js');
</script>
<div id="bootstrap"></div>
<div id="app"></div>
</body>
</html>

View File

@ -1,10 +0,0 @@
const express = require("express");
const app = express();
app.use(express.static(__dirname + "/dist"));
app.listen(8088, () => console.log("Listening on port 8088!"));
module.exports = app;

View File

@ -1,17 +0,0 @@
const hotClient = require('webpack-hot-client');
const middleware = require('webpack-dev-middleware');
const webpack = require('webpack');
const config = require('../webpack.config');
const app = require('../stubs');
const compiler = webpack(config);
const { publicPath } = config.output;
const options = { }; // webpack-hot-client options
// we recommend calling the client _before_ adding the dev middleware
const client = hotClient(compiler, options);
const { server } = client;
server.on('listening', () => {
app.use(middleware(compiler, { publicPath, historyApiFallback: true }));
});

View File

@ -5,30 +5,24 @@ const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const outputDirectory = 'dist';
const pkg = require('./package.json')
module.exports = {
mode: 'development',
mode: "development",
entry: {
bootstrap: ['./src/main.js']
index: "./src/main.ts"
},
output: {
filename: '[name].js',
library: "bootstrap",
path: path.resolve(__dirname, outputDirectory),
globalObject: `(typeof self !== 'undefined' ? self : this)`
libraryExport: "default",
publicPath: `/boorstrap/${pkg.version}/`
},
node: {
fs: 'empty'
},
plugins: [
new CleanWebpackPlugin(),
new webpack.DefinePlugin({
'typeof window': JSON.stringify('object')
})
],
devtool: '#source-map',
//devtool: 'none',
plugins: [new CleanWebpackPlugin()],
resolve: {
modules: ['node_modules', 'src'],
extensions: ['.webpack.js', '.web.js', '.ts', '.tsx', '.js', '.css']
extensions: [".jsx", ".js"]
},
module: {
@ -36,13 +30,12 @@ module.exports = {
{ parser: { system: false } },
{
test: /\.tsx?$/,
loader: 'awesome-typescript-loader'
loader: "awesome-typescript-loader"
},
{
test: /\.(jpe?g|gif|png|svg|woff|ttf|eot|wav|mp3)$/,
loader: 'file-loader'
loader: "file-loader"
}
]
}
};