Commit 710b7196 by Иван Кубота

3/4

parent c207cb35
...@@ -24,7 +24,7 @@ var cache = {}; ...@@ -24,7 +24,7 @@ var cache = {};
const serveBundle = async function(tpl, res){ const serveBundle = async function(tpl, res){
var fileName = dir(pack.src, pack.entry.js); var fileName = dir(pack.src, pack.entry.js);
var posixName = path.posix.join(pack.src, pack.entry.js); var posixName = pack.entry.js;//path.posix.join(pack.src, );
console.log(fileName) console.log(fileName)
fs.readFile(fileName, function(err, jsx) { fs.readFile(fileName, function(err, jsx) {
if(err){ if(err){
...@@ -37,7 +37,7 @@ const serveBundle = async function(tpl, res){ ...@@ -37,7 +37,7 @@ const serveBundle = async function(tpl, res){
'<script src="'+cacheEntry+'"></script>') '<script src="'+cacheEntry+'"></script>')
); );
transformJSX(jsx+'', path.posix.join(pack.src, pack.entry.js), function(err, result) { transformJSX(jsx+'', pack.entry.js, function(err, result) {
if(err){ if(err){
console.error(err) console.error(err)
cache[ '/' + cacheEntry ] = JSON.stringify(err, null,2); cache[ '/' + cacheEntry ] = JSON.stringify(err, null,2);
...@@ -99,12 +99,13 @@ var transformServe = function(dir) { ...@@ -99,12 +99,13 @@ var transformServe = function(dir) {
if (req.url.substr(-5) === '.scss') { if (req.url.substr(-5) === '.scss') {
// not secure // not secure
fs.readFile(path.join(__dirname,req.url), function(err, data){ console.log('scss', dir, req.url, __dirname)
fs.readFile(path.join(__dirname,dir,req.url), function(err, data){
if( err ){ if( err ){
next(); next();
}else{ }else{
sass.render({ sass.render({
file: path.join(__dirname,req.url), file: path.join(__dirname,dir,req.url),
sourceMap: true, sourceMap: true,
importer: function(url, prev, done) { importer: function(url, prev, done) {
console.log(url, prev, done) console.log(url, prev, done)
...@@ -113,12 +114,15 @@ var transformServe = function(dir) { ...@@ -113,12 +114,15 @@ var transformServe = function(dir) {
// 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
setTimeout(function(result){ setTimeout(function(result){
var name = path.resolve(path.dirname(prev), url) var name = path.resolve(path.dirname(prev), url);
var displayName = path.relative(path.join(__dirname,dir),path.resolve(path.dirname(prev), url))
done({ done({
file: name, // only one of them is required, see section Special Behaviours. file: displayName, // only one of them is required, see section Special Behaviours.
contents: fs.readFileSync(name)+'' contents: fs.readFileSync(name)+''
}); });
console.log({name, __dirname, dir, url, prev})
},10); },10);
// OR // OR
//var result = someSyncFunction(url, prev); //var result = someSyncFunction(url, prev);
...@@ -136,17 +140,24 @@ var transformServe = function(dir) { ...@@ -136,17 +140,24 @@ var transformServe = function(dir) {
} }
}); });
}else if (req.url.substr(-4) === '.jsx') { }else if (req.url.substr(-4) === '.jsx') {
console.log('Serve jsx', dir, req.url)
fs.readFile(path.join(dir, req.url), function(err, data){ fs.readFile(path.join(dir, req.url), function(err, data){
if( err ){ if( err ){
console.log('No jsx', err)
next(); next();
}else{ }else{
console.log('Transform jsx', req.url);
transformJSX(data+'', req.url, function(err, result) { transformJSX(data+'', req.url, function(err, result) {
if(err){ if(err){
console.log('Error in transforming jsx', err);
res.end(err.message+'\n'+err.stack) res.end(err.message+'\n'+err.stack)
}else{ }else{
cache[ req.url + '.map' ] = JSON.stringify( result.map ); cache[ req.url + '.map' ] = JSON.stringify( result.map );
res.set( 'SourceMap', req.url + '.map' ); res.set( 'SourceMap', req.url + '.map' );
res.end( result.code ) res.end( result.code );
debugger;
} }
}) })
} }
...@@ -159,6 +170,7 @@ var transformServe = function(dir) { ...@@ -159,6 +170,7 @@ var transformServe = function(dir) {
}; };
app.use(transformServe('public')); app.use(transformServe('public'));
app.use(transformServe('src'));
var lives = []; var lives = [];
app.use('/', function(req, res, next) { app.use('/', function(req, res, next) {
console.log(req.originalUrl) console.log(req.originalUrl)
......
...@@ -125,10 +125,10 @@ ...@@ -125,10 +125,10 @@
} }
}; };
var log = console.log;
var log = function() { /*var log = function() {
console.log.apply(console, ['Define'].concat([].slice.call(arguments))); console.log.apply(console, ['Define'].concat([].slice.call(arguments)));
}; };*/
var head = document.getElementsByTagName('head')[0]; var head = document.getElementsByTagName('head')[0];
var cssLoader = function(fileName) { var cssLoader = function(fileName) {
...@@ -137,6 +137,7 @@ ...@@ -137,6 +137,7 @@
link.setAttribute('type', 'text/css'); link.setAttribute('type', 'text/css');
link.setAttribute('href', fileName); link.setAttribute('href', fileName);
head.appendChild(link); head.appendChild(link);
return true;
}; };
var jsLoader = function(fileName) { var jsLoader = function(fileName) {
fileName = fileName.replace(/src\//,''); fileName = fileName.replace(/src\//,'');
......
...@@ -233,7 +233,7 @@ ...@@ -233,7 +233,7 @@
// ES 6 consts are not in global scope. So we can not just add vars to window // ES 6 consts are not in global scope. So we can not just add vars to window
var pointer = first? var pointer = first?
new Function('g', 'return typeof '+first+' !== "undefined"?'+first+':(glob["'+first+'"] = {})')(glob) new Function('glob', 'return typeof '+first+' !== "undefined"?'+first+':(glob["'+first+'"] = {})')(glob)
:glob; :glob;
tokens.reduce(function(pointer, token, i, full) { tokens.reduce(function(pointer, token, i, full) {
......
data = null; data = null;
import './main.scss'; import './main.scss';
import {Button} from './view/cmp/button.jsx' import {Button} from '/view/cmp/button.jsx'
export default function() { export default function() {
let tagField, exportEl; let tagField, exportEl;
......
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