support imports
This commit is contained in:
parent
aa0f774f1d
commit
33711c8db2
|
@ -4,9 +4,8 @@ var Plugins = require('./plugins.js');
|
|||
var utils = require('../utils/utils.js');
|
||||
var Npm = require('../pipeline/npm.js');
|
||||
let currentWeb3Version = require('../../package.json').dependencies.web3.replace("^","");
|
||||
const webpack = require("webpack");
|
||||
|
||||
// TODO: add wrapper for fs so it can also work in the browser
|
||||
// can work with both read and save
|
||||
var Config = function(options) {
|
||||
this.env = options.env;
|
||||
this.blockchainConfig = {};
|
||||
|
@ -336,11 +335,55 @@ Config.prototype.loadFiles = function(files) {
|
|||
//} else if (file === 'abi.js') {
|
||||
// readFiles.push({filename: file, content: "", path: file});
|
||||
} else {
|
||||
if (file.indexOf('.') >= 0) {
|
||||
|
||||
if (file.indexOf('index.js') >= 0) {
|
||||
//if (file.indexOf('.js') >= 0) {
|
||||
readFiles.push(new File({filename: file, type: "custom", path: file, resolver: function(callback) {
|
||||
console.log("---");
|
||||
console.log(fs.dappPath());
|
||||
console.log(file);
|
||||
console.log("---");
|
||||
webpack({
|
||||
entry: utils.joinPath(fs.dappPath(), file),
|
||||
output: {
|
||||
//libraryTarget: 'umd',
|
||||
path: utils.joinPath(fs.dappPath(), '.embark'),
|
||||
//filename: 'my-first-webpack.bundle.js'
|
||||
filename: file
|
||||
},
|
||||
externals: function(context, request, callback) {
|
||||
if (request == "MyLib") {
|
||||
console.log("MyLib Detected!");
|
||||
return callback(null, "{foo: 'hello'}");
|
||||
}
|
||||
callback();
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: [
|
||||
{ loader: "style-loader" },
|
||||
{ loader: "css-loader" }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}).run((err, stats) => {
|
||||
console.log(err, stats);
|
||||
//return callback(fs.readFileSync('./.embark/my-first-webpack.bundle.js').toString());
|
||||
return callback(fs.readFileSync('./.embark/' + file).toString());
|
||||
});
|
||||
}}));
|
||||
} else {
|
||||
readFiles.push(new File({filename: file, type: "dapp_file", path: file}));
|
||||
} else if (file[0] === '$') {
|
||||
//readFiles.push(new File({filename: file, type: 'embark_internal', path: file}));
|
||||
}
|
||||
|
||||
//if (file.indexOf('.') >= 0) {
|
||||
// readFiles.push(new File({filename: file, type: "dapp_file", path: file}));
|
||||
//} else if (file[0] === '$') {
|
||||
// //readFiles.push(new File({filename: file, type: 'embark_internal', path: file}));
|
||||
//}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -46,5 +46,6 @@ module.exports = {
|
|||
readJSONSync: readJSONSync,
|
||||
writeJSONSync: writeJSONSync,
|
||||
existsSync: existsSync,
|
||||
embarkPath: embarkPath
|
||||
embarkPath: embarkPath,
|
||||
dappPath: dappPath
|
||||
};
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
"chokidar": "^1.6.0",
|
||||
"colors": "^1.1.2",
|
||||
"commander": "^2.8.1",
|
||||
"css-loader": "^0.28.7",
|
||||
"ejs": "^2.5.7",
|
||||
"ethereumjs-testrpc": "3.9.2",
|
||||
"finalhandler": "^0.5.0",
|
||||
|
@ -37,6 +38,7 @@
|
|||
"serve-static": "^1.11.1",
|
||||
"shelljs": "^0.5.0",
|
||||
"solc": "0.4.17",
|
||||
"style-loader": "^0.19.0",
|
||||
"tar": "^3.1.5",
|
||||
"toposort": "^1.0.0",
|
||||
"underscore": "^1.8.3",
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
body {
|
||||
background-color: black;
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
const FOO = "dude";
|
||||
|
||||
export default FOO;
|
|
@ -1,5 +1,12 @@
|
|||
/*globals $, SimpleStorage, document*/
|
||||
|
||||
import Test2 from 'MyLib';
|
||||
|
||||
import test3 from './foo';
|
||||
import './foo.css';
|
||||
|
||||
window.test_3 = test3;
|
||||
|
||||
var addToLog = function(id, txt) {
|
||||
$(id + " .logs").append("<br>" + txt);
|
||||
};
|
||||
|
@ -8,6 +15,9 @@ var addToLog = function(id, txt) {
|
|||
// Blockchain example
|
||||
// ===========================
|
||||
$(document).ready(function() {
|
||||
console.log([1,2,3].map(v => v + 1));
|
||||
alert('hello');
|
||||
window.test_2 = Test2;
|
||||
|
||||
$("#blockchain button.set").click(function() {
|
||||
var value = parseInt($("#blockchain input.text").val(), 10);
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
{
|
||||
"contracts": ["app/contracts/**"],
|
||||
"app": {
|
||||
"js/webpack_test.js": "app/js/index.js",
|
||||
"css/app.css": ["app/css/**"],
|
||||
"images/": ["app/images/**"],
|
||||
"js/app.js": ["embark.js", "app/js/_vendor/jquery.min.js", "app/js/_vendor/bootstrap.min.js", "app/js/**", "!app/js/test.js"],
|
||||
"js/app.js": ["embark.js", "app/js/_vendor/jquery.min.js", "app/js/_vendor/bootstrap.min.js", "app/js/**", "!app/js/test.js", "!app/js/foo.js", "!app/js/foo.css"],
|
||||
"js/embark.js": ["embark.js"],
|
||||
"js/abi.js": "abi.js",
|
||||
"js/test.js": ["embark.js", "app/js/_vendor/jquery.min.js", "app/js/_vendor/async.min.js", "app/js/test.js"],
|
||||
|
|
Loading…
Reference in New Issue