Commit c207cb35 by Иван Кубота

2/3 working

parent fa381086
...@@ -38,7 +38,6 @@ const serveBundle = async function(tpl, res){ ...@@ -38,7 +38,6 @@ const serveBundle = async function(tpl, res){
); );
transformJSX(jsx+'', path.posix.join(pack.src, pack.entry.js), function(err, result) { transformJSX(jsx+'', path.posix.join(pack.src, pack.entry.js), function(err, result) {
debugger
if(err){ if(err){
console.error(err) console.error(err)
cache[ '/' + cacheEntry ] = JSON.stringify(err, null,2); cache[ '/' + cacheEntry ] = JSON.stringify(err, null,2);
...@@ -88,7 +87,7 @@ var transformJSX = function(code, fileName, cb) { ...@@ -88,7 +87,7 @@ var transformJSX = function(code, fileName, cb) {
} }
} ); } );
}; };
var sass = require('node-sass');
var transformServe = function(dir) { var transformServe = function(dir) {
return function (req, res, next) { return function (req, res, next) {
if (req.url in cache) { if (req.url in cache) {
...@@ -99,29 +98,41 @@ var transformServe = function(dir) { ...@@ -99,29 +98,41 @@ var transformServe = function(dir) {
}*/ }*/
if (req.url.substr(-5) === '.scss') { if (req.url.substr(-5) === '.scss') {
fs.readFile(path.join(dir, req.url), function(err, data){ // not secure
fs.readFile(path.join(__dirname,req.url), function(err, data){
if( err ){ if( err ){
next(); next();
}else{ }else{
sass.render({ sass.render({
file: path.join(dir, req.url), file: path.join(__dirname,req.url),
sourceMap: true, sourceMap: true,
importer: function(url, prev, done) { importer: function(url, prev, done) {
console.log(url, prev, done)
// url is the path in import as is, which LibSass encountered. // url is the path in import as is, which LibSass encountered.
// prev is the previously resolved path. // prev is the previously resolved path.
// done is an optional callback, either consume it or return value synchronously. // done is an optional callback, either consume it or return value synchronously.
// this.options contains this options hash // this.options contains this options hash
someAsyncFunction(url, prev, function(result){ setTimeout(function(result){
var name = path.resolve(path.dirname(prev), url)
done({ done({
file: result.path, // only one of them is required, see section Special Behaviours. file: name, // only one of them is required, see section Special Behaviours.
contents: result.data contents: fs.readFileSync(name)+''
}); });
}); },10);
// OR // OR
var result = someSyncFunction(url, prev); //var result = someSyncFunction(url, prev);
return {file: result.path, contents: result.data}; //return {file: result.path, contents: result.data};
}
}, function(err, result) {
if(err){
const errorText = `Error at ${err.file}:\n`+err.formatted;
return res.end(errorText)
} }
}, function(err, result) { /*...*/ }); res.header('Content-Type', 'text/css');
res.end(result.css)
debugger
/*...*/ });
} }
}); });
}else if (req.url.substr(-4) === '.jsx') { }else if (req.url.substr(-4) === '.jsx') {
...@@ -172,7 +183,7 @@ app.use('/', function(req, res, next) { ...@@ -172,7 +183,7 @@ app.use('/', function(req, res, next) {
} }
}); });
app.use(App.static(dir(pack.public))) app.use(App.static(dir(pack.public)))
app.use(App.static(dir(pack.src))) //app.use(App.static(dir(pack.src)))
......
...@@ -20,9 +20,7 @@ ...@@ -20,9 +20,7 @@
"devDependencies": { "devDependencies": {
"@babel/core": "^7.8.3", "@babel/core": "^7.8.3",
"@babel/plugin-transform-modules-amd": "^7.8.3", "@babel/plugin-transform-modules-amd": "^7.8.3",
"@babel/plugin-transform-react-jsx": "^7.8.3", "@babel/plugin-transform-react-jsx": "^7.8.3"
"babel-plugin-async-import": "ssh://git@github.com:bernardmcmanus/babel-plugin-async-import.git",
"babel-plugin-func-wrap": "^1.1.0"
}, },
"plugins": [ "plugins": [
"@babel/plugin-transform-react-jsx" "@babel/plugin-transform-react-jsx"
......
...@@ -138,10 +138,22 @@ ...@@ -138,10 +138,22 @@
link.setAttribute('href', fileName); link.setAttribute('href', fileName);
head.appendChild(link); head.appendChild(link);
}; };
var jsLoader = function(fileName) {
fileName = fileName.replace(/src\//,'');
var script = document.createElement('script');
script.setAttribute('type', script.type = 'text/javascript');
script.onload = function(){
};
script.setAttribute('src', script.src = fileName);
head.appendChild(script);
};
var InstantLoaders = [ var InstantLoaders = [
{name: '.scss', loader: cssLoader}, {name: '.scss', loader: cssLoader},
{name: '.css', loader: cssLoader}, {name: '.css', loader: cssLoader},
{name: '.jsx', loader: jsLoader},
{name: '.js', loader: jsLoader},
]; ];
var Ready = function() {}; Ready.prototype = {ready: true}; var Ready = function() {}; Ready.prototype = {ready: true};
...@@ -154,8 +166,10 @@ ...@@ -154,8 +166,10 @@
for( var i = 0, _i = InstantLoaders.length; i < _i; i++ ){ for( var i = 0, _i = InstantLoaders.length; i < _i; i++ ){
const instantLoader = InstantLoaders[ i ]; const instantLoader = InstantLoaders[ i ];
if(this.fileName.substr(-instantLoader.name.length).toLowerCase()===instantLoader.name){ if(this.fileName.substr(-instantLoader.name.length).toLowerCase()===instantLoader.name){
instantLoader.loader(this.fileName); if(instantLoader.loader(this.fileName)) {
return true; return true;
}
break;
} }
} }
return false; return false;
...@@ -173,13 +187,14 @@ ...@@ -173,13 +187,14 @@
}; };
var exec = function(def) { var exec = function(def) {
var exports = {}; var exports = {};
defined[def.fileName] = def.fn.apply(null, def.deps.map(function(dep) { def.fn.apply(null, def.deps.map(function(dep) {
if(dep === 'exports'){ if(dep === 'exports'){
return exports; return exports;
} }
return defined[resolve(def.fileName, dep)]; return defined[resolve(def.fileName, dep)];
})); }));
defined[def.fileName] = exports;
wait[def.fileName] = new Ready(); wait[def.fileName] = new Ready();
for( var i = 0, _i = wait.length; i < _i; i++ ){ for( var i = 0, _i = wait.length; i < _i; i++ ){
var waitElement = wait[ i ]; var waitElement = wait[ i ];
......
$black: #000;
$white: #fff;
...@@ -59,12 +59,9 @@ ...@@ -59,12 +59,9 @@
<script> <script>
initDataProvider($DATA$); initDataProvider($DATA$);
debugger
define('begin', ['src/main.jsx'], function(main) { define('begin', ['src/main.jsx'], function(main) {
debugger main.default();
main();
}); });
</script> </script>
</body> </body>
</html> </html>
\ No newline at end of file
data = null; data = null;
import './main.scss'; import './main.scss';
import {Button} from './view/cmp/button.jsx'
export default function() { export default function() {
let tagField, exportEl; let tagField, exportEl;
...@@ -7,7 +8,7 @@ export default function() { ...@@ -7,7 +8,7 @@ export default function() {
renderTo: document.body, renderTo: document.body,
cls: 'content' cls: 'content'
}, },
<Button value={22}/>,
div({ div({
cls: 'main-menu' cls: 'main-menu'
}, },
......
@import "base.scss";
body { body {
font-family: Verdana, Serif; font-family: Verdana, Serif;
} }
......
import './button.scss'; import './button.scss';
D.declare('cmp.Button', function(cfg) { export const Button = D.declare('cmp.Button', function(cfg) {
return <input type='button' {...cfg} cls='button'/> return <input type='button' {...cfg} cls='button'/>
}); });
\ No newline at end of file
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
"@babel/types" "^7.8.3" "@babel/types" "^7.8.3"
lodash "^4.17.13" lodash "^4.17.13"
"@babel/helper-plugin-utils@^7.8.0", "@babel/helper-plugin-utils@^7.8.3": "@babel/helper-plugin-utils@^7.8.3":
version "7.8.3" version "7.8.3"
resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.8.3.tgz#9ea293be19babc0f52ff8ca88b34c3611b208670" resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.8.3.tgz#9ea293be19babc0f52ff8ca88b34c3611b208670"
integrity sha512-j+fq49Xds2smCUNYmEHF9kGNkhbet6yVIBp4e6oeQpH1RUs/Ir06xUKzDjDkGcaaokPiTNs2JBWHjaE4csUkZQ== integrity sha512-j+fq49Xds2smCUNYmEHF9kGNkhbet6yVIBp4e6oeQpH1RUs/Ir06xUKzDjDkGcaaokPiTNs2JBWHjaE4csUkZQ==
...@@ -126,13 +126,6 @@ ...@@ -126,13 +126,6 @@
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.8.3.tgz#790874091d2001c9be6ec426c2eed47bc7679081" resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.8.3.tgz#790874091d2001c9be6ec426c2eed47bc7679081"
integrity sha512-/V72F4Yp/qmHaTALizEm9Gf2eQHV3QyTL3K0cNfijwnMnb1L+LDlAubb/ZnSdGAVzVSWakujHYs1I26x66sMeQ== integrity sha512-/V72F4Yp/qmHaTALizEm9Gf2eQHV3QyTL3K0cNfijwnMnb1L+LDlAubb/ZnSdGAVzVSWakujHYs1I26x66sMeQ==
"@babel/plugin-syntax-dynamic-import@^7.2.0":
version "7.8.3"
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-dynamic-import/-/plugin-syntax-dynamic-import-7.8.3.tgz#62bf98b2da3cd21d626154fc96ee5b3cb68eacb3"
integrity sha512-5gdGbFon+PszYzqs83S3E5mpi7/y/8M9eC90MRTZfduQOYW76ig6SOSPNe41IG5LoP3FGBn2N0RjVDSQiS94kQ==
dependencies:
"@babel/helper-plugin-utils" "^7.8.0"
"@babel/plugin-syntax-jsx@^7.8.3": "@babel/plugin-syntax-jsx@^7.8.3":
version "7.8.3" version "7.8.3"
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.8.3.tgz#521b06c83c40480f1e58b4fd33b92eceb1d6ea94" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.8.3.tgz#521b06c83c40480f1e58b4fd33b92eceb1d6ea94"
...@@ -168,7 +161,7 @@ ...@@ -168,7 +161,7 @@
"@babel/helper-plugin-utils" "^7.8.3" "@babel/helper-plugin-utils" "^7.8.3"
"@babel/plugin-syntax-jsx" "^7.8.3" "@babel/plugin-syntax-jsx" "^7.8.3"
"@babel/template@^7.4.4", "@babel/template@^7.8.3": "@babel/template@^7.8.3":
version "7.8.3" version "7.8.3"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.8.3.tgz#e02ad04fe262a657809327f578056ca15fd4d1b8" resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.8.3.tgz#e02ad04fe262a657809327f578056ca15fd4d1b8"
integrity sha512-04m87AcQgAFdvuoyiQ2kgELr2tV8B4fP/xJAVUL3Yb3bkNdMedD3d0rlSQr3PegP0cms3eHjl1F7PWlvWbU8FQ== integrity sha512-04m87AcQgAFdvuoyiQ2kgELr2tV8B4fP/xJAVUL3Yb3bkNdMedD3d0rlSQr3PegP0cms3eHjl1F7PWlvWbU8FQ==
...@@ -367,13 +360,6 @@ aws4@^1.8.0: ...@@ -367,13 +360,6 @@ aws4@^1.8.0:
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.9.1.tgz#7e33d8f7d449b3f673cd72deb9abdc552dbe528e" resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.9.1.tgz#7e33d8f7d449b3f673cd72deb9abdc552dbe528e"
integrity sha512-wMHVg2EOHaMRxbzgFJ9gtjOOCrI80OHLG14rxi28XwOW8ux6IiEbRCGGGqCtdAIg4FQCbW20k9RsT4y3gJlFug== integrity sha512-wMHVg2EOHaMRxbzgFJ9gtjOOCrI80OHLG14rxi28XwOW8ux6IiEbRCGGGqCtdAIg4FQCbW20k9RsT4y3gJlFug==
"babel-plugin-async-import@ssh://git@github.com:bernardmcmanus/babel-plugin-async-import.git":
version "2.1.0"
resolved "ssh://git@github.com:bernardmcmanus/babel-plugin-async-import.git#55aad29d8947247deffc56f3d0c38a9bf9773cb0"
dependencies:
"@babel/plugin-syntax-dynamic-import" "^7.2.0"
"@babel/template" "^7.4.4"
babel-plugin-dynamic-import-node@^2.3.0: babel-plugin-dynamic-import-node@^2.3.0:
version "2.3.0" version "2.3.0"
resolved "https://registry.yarnpkg.com/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.0.tgz#f00f507bdaa3c3e3ff6e7e5e98d90a7acab96f7f" resolved "https://registry.yarnpkg.com/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.0.tgz#f00f507bdaa3c3e3ff6e7e5e98d90a7acab96f7f"
...@@ -381,11 +367,6 @@ babel-plugin-dynamic-import-node@^2.3.0: ...@@ -381,11 +367,6 @@ babel-plugin-dynamic-import-node@^2.3.0:
dependencies: dependencies:
object.assign "^4.1.0" object.assign "^4.1.0"
babel-plugin-func-wrap@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/babel-plugin-func-wrap/-/babel-plugin-func-wrap-1.1.0.tgz#302e479eb9cc15ddb3db2c65f4b48a748b6e69a1"
integrity sha512-C6e8mUVg3c/o9LwGk3tYvRq8MlyZdqimtQHzcZdsb2nEywlOkmp3zlCllo8QAmcsnwSB30iEcZ6rr2AhhTwO3w==
balanced-match@^1.0.0: balanced-match@^1.0.0:
version "1.0.0" version "1.0.0"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment