support special imports

This commit is contained in:
Iuri Matias 2017-12-10 09:06:11 -05:00
parent 038f57e7d2
commit 92e22ea519
3 changed files with 72 additions and 42 deletions

View File

@ -1,10 +1,3 @@
/*jshint esversion: 6 */
//var Ipfs = require('./ipfs.js');
//=========================================================
// Embark Smart Contracts
//=========================================================
var EmbarkJS = {}; var EmbarkJS = {};
EmbarkJS.isNewWeb3 = function() { EmbarkJS.isNewWeb3 = function() {

View File

@ -3,6 +3,7 @@ var File = require('./file.js');
var Plugins = require('./plugins.js'); var Plugins = require('./plugins.js');
var utils = require('../utils/utils.js'); var utils = require('../utils/utils.js');
var Npm = require('../pipeline/npm.js'); var Npm = require('../pipeline/npm.js');
let async = require('async');
let currentWeb3Version = require('../../package.json').dependencies.web3.replace("^",""); let currentWeb3Version = require('../../package.json').dependencies.web3.replace("^","");
const webpack = require("webpack"); const webpack = require("webpack");
@ -344,47 +345,84 @@ Config.prototype.loadFile = function(files) {
if (file.indexOf('.js') >= 0) { if (file.indexOf('.js') >= 0) {
//if (file.indexOf('.js') >= 0) { //if (file.indexOf('.js') >= 0) {
readFiles.push(new File({filename: file, type: "custom", path: file, resolver: function(callback) { readFiles.push(new File({filename: file, type: "custom", path: file, resolver: function(fileCallback) {
console.log("---"); console.log("---");
console.log(fs.dappPath()); console.log(fs.dappPath());
console.log(file); console.log(file);
console.log("---"); console.log("---");
webpack({
entry: utils.joinPath(fs.dappPath(), file), let importsList = {};
output: { async.waterfall([
//libraryTarget: 'umd', function findImports(next) {
path: utils.joinPath(fs.dappPath(), '.embark'), webpack({
//filename: 'my-first-webpack.bundle.js' entry: utils.joinPath(fs.dappPath(), file),
filename: file output: {
}, libraryTarget: 'umd',
externals: function(context, request, callback) { path: utils.joinPath(fs.dappPath(), '.embark'),
if (request == "MyLib") { filename: file
console.log("MyLib Detected!"); },
return callback(null, "{foo: 'hello'}"); externals: function(context, request, callback) {
} if (request === utils.joinPath(fs.dappPath(), file)) {
if (request == "Embark/EmbarkJS") { callback();
console.log("EmbarkJS Detected!"); } else {
return callback(null, "{foo: 'hello'}"); if (request === "Embark/EmbarkJS") {
} importsList["Embark/EmbarkJS"] = fs.embarkPath("js/embark.js");
callback(); } else if (request === "Embark/test") {
}, importsList["Embark/test"] = fs.embarkPath("js/test.js");
module: { }
rules: [ callback(null, "amd " + Math.random());
{ }
test: /\.css$/, },
use: [ module: {
{ loader: "style-loader" }, rules: [
{ loader: "css-loader" } {
test: /\.css$/,
use: [
{ loader: "style-loader" },
{ loader: "css-loader" }
]
}
] ]
} }
] }).run((err, stats) => {
next();
});
},
function runWebpack(next) {
webpack({
entry: utils.joinPath(fs.dappPath(), file),
output: {
libraryTarget: 'umd',
path: utils.joinPath(fs.dappPath(), '.embark'),
filename: file
},
resolve: {
alias: importsList
},
module: {
rules: [
{
test: /\.css$/,
use: [
{ loader: "style-loader" },
{ loader: "css-loader" }
]
}
]
}
}).run((err, stats) => {
next();
});
} }
}).run((err, stats) => {
console.log(err, stats); ], function(err, _result) {
//return callback(fs.readFileSync('./.embark/my-first-webpack.bundle.js').toString()); fileCallback(fs.readFileSync('./.embark/' + file).toString());
return callback(fs.readFileSync('./.embark/' + file).toString());
}); });
}})); }}));
} else { } else {
readFiles.push(new File({filename: file, type: "dapp_file", path: file})); readFiles.push(new File({filename: file, type: "dapp_file", path: file}));
} }

View File

@ -2,8 +2,8 @@
import $ from './_vendor/jquery.min'; import $ from './_vendor/jquery.min';
//import EmbarkJS from 'Embark/EmbarkJS'; //import EmbarkJS from 'Embark/EmbarkJS';
import EmbarkJS from 'Embark/EmbarkJS';
import Test2 from 'MyLib'; console.log(EmbarkJS);
import test3 from './foo'; import test3 from './foo';
import './foo.css'; import './foo.css';
@ -20,7 +20,6 @@ var addToLog = function(id, txt) {
$(document).ready(function() { $(document).ready(function() {
console.log([1,2,3].map(v => v + 1)); console.log([1,2,3].map(v => v + 1));
alert('hello'); alert('hello');
window.test_2 = Test2;
$("#blockchain button.set").click(function() { $("#blockchain button.set").click(function() {
var value = parseInt($("#blockchain input.text").val(), 10); var value = parseInt($("#blockchain input.text").val(), 10);