mirror of https://github.com/embarklabs/embark.git
improve full support for es6
This commit is contained in:
parent
a322d03053
commit
be1c5badd8
|
@ -7,6 +7,11 @@ var utils = require('../utils/utils.js');
|
||||||
//let currentWeb3Version = require('../../package.json').dependencies.web3.replace("^","");
|
//let currentWeb3Version = require('../../package.json').dependencies.web3.replace("^","");
|
||||||
const webpack = require("webpack");
|
const webpack = require("webpack");
|
||||||
|
|
||||||
|
require("babel-preset-react");
|
||||||
|
require("babel-preset-es2015");
|
||||||
|
require("babel-preset-es2016");
|
||||||
|
require("babel-preset-es2017");
|
||||||
|
|
||||||
class Pipeline {
|
class Pipeline {
|
||||||
|
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
|
@ -57,6 +62,42 @@ class Pipeline {
|
||||||
path: utils.joinPath(fs.dappPath(), '.embark'),
|
path: utils.joinPath(fs.dappPath(), '.embark'),
|
||||||
filename: file.filename
|
filename: file.filename
|
||||||
},
|
},
|
||||||
|
resolve: {
|
||||||
|
alias: importsList,
|
||||||
|
modules: [
|
||||||
|
fs.embarkPath('node_modules'),
|
||||||
|
utils.joinPath(fs.dappPath(), 'node_modules')
|
||||||
|
]
|
||||||
|
},
|
||||||
|
externals: function(context, request, callback) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}).run((_err, _stats) => {
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
function changeCwd(next) {
|
||||||
|
realCwd = process.env.PWD;
|
||||||
|
process.chdir(fs.embarkPath(''));
|
||||||
|
next();
|
||||||
|
},
|
||||||
|
|
||||||
|
function findImportsPhase2(next) {
|
||||||
|
webpack({
|
||||||
|
entry: utils.joinPath(fs.dappPath(), file.filename),
|
||||||
|
output: {
|
||||||
|
libraryTarget: 'umd',
|
||||||
|
path: utils.joinPath(fs.dappPath(), '.embark'),
|
||||||
|
filename: file.filename
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
alias: importsList,
|
||||||
|
modules: [
|
||||||
|
fs.embarkPath('node_modules'),
|
||||||
|
utils.joinPath(fs.dappPath(), 'node_modules')
|
||||||
|
]
|
||||||
|
},
|
||||||
externals: function(context, request, callback) {
|
externals: function(context, request, callback) {
|
||||||
if (request === utils.joinPath(fs.dappPath(), file.filename)) {
|
if (request === utils.joinPath(fs.dappPath(), file.filename)) {
|
||||||
callback();
|
callback();
|
||||||
|
@ -70,16 +111,38 @@ class Pipeline {
|
||||||
}
|
}
|
||||||
callback(null, "amd " + Math.random());
|
callback(null, "amd " + Math.random());
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
test: /\.css$/,
|
||||||
|
use: [{loader: "style-loader"}, {loader: "css-loader"}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /\.scss$/,
|
||||||
|
use: [{loader: "style-loader"}, {loader: "css-loader"}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
|
||||||
|
loader: 'url-loader?limit=100000'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /\.js$/,
|
||||||
|
loader: "babel-loader",
|
||||||
|
exclude: /(node_modules|bower_components)/,
|
||||||
|
options: {
|
||||||
|
presets: ['es2016', 'es2017', 'react'],
|
||||||
|
plugins: [
|
||||||
|
"babel-plugin-webpack-aliases"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
}).run((_err, _stats) => {
|
}).run((_err, _stats) => {
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
},
|
|
||||||
|
|
||||||
function changeCwd(next) {
|
|
||||||
realCwd = process.env.PWD;
|
|
||||||
process.chdir(fs.embarkPath(''));
|
|
||||||
next();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
function runWebpack(next) {
|
function runWebpack(next) {
|
||||||
|
@ -117,9 +180,20 @@ class Pipeline {
|
||||||
{
|
{
|
||||||
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
|
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
|
||||||
loader: 'url-loader?limit=100000'
|
loader: 'url-loader?limit=100000'
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
test: /\.js$/,
|
||||||
|
loader: "babel-loader",
|
||||||
|
exclude: /(node_modules|bower_components)/,
|
||||||
|
options: {
|
||||||
|
presets: ['es2016', 'es2017', 'react'],
|
||||||
|
plugins: [
|
||||||
|
"babel-plugin-webpack-aliases"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
}).run((_err, _stats) => {
|
}).run((_err, _stats) => {
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
@ -192,16 +266,16 @@ class Pipeline {
|
||||||
}
|
}
|
||||||
|
|
||||||
buildContracts(contractsJSON) {
|
buildContracts(contractsJSON) {
|
||||||
fs.mkdirpSync(this.buildDir + 'contracts');
|
fs.mkdirpSync(utils.joinPath(fs.dappPath(), this.buildDir, 'contracts'));
|
||||||
|
|
||||||
for (let className in contractsJSON) {
|
for (let className in contractsJSON) {
|
||||||
let contract = contractsJSON[className];
|
let contract = contractsJSON[className];
|
||||||
fs.writeJSONSync(this.buildDir + 'contracts/' + className + ".json", contract, {spaces: 2});
|
fs.writeJSONSync(utils.joinPath(fs.dappPath(), this.buildDir, 'contracts', className + ".json"), contract, {spaces: 2});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buildContractJS(contractName) {
|
buildContractJS(contractName) {
|
||||||
let contractJSON = fs.readFileSync('dist/contracts/' + contractName + '.json').toString();
|
let contractJSON = fs.readFileSync(utils.joinPath(fs.dappPath(), this.buildDir, 'contracts', contractName + '.json')).toString();
|
||||||
|
|
||||||
let contractCode = "";
|
let contractCode = "";
|
||||||
contractCode += "import web3 from 'Embark/web3';\n";
|
contractCode += "import web3 from 'Embark/web3';\n";
|
||||||
|
|
|
@ -21,6 +21,13 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": "^2.0.1",
|
"async": "^2.0.1",
|
||||||
|
"babel-core": "^6.26.0",
|
||||||
|
"babel-loader": "^7.1.2",
|
||||||
|
"babel-preset-es2015": "^6.24.1",
|
||||||
|
"babel-preset-es2016": "^6.24.1",
|
||||||
|
"babel-preset-es2017": "6.24.1",
|
||||||
|
"babel-preset-react": "^6.24.1",
|
||||||
|
"babel-plugin-webpack-aliases": "^1.1.3",
|
||||||
"blessed": "^0.1.81",
|
"blessed": "^0.1.81",
|
||||||
"chokidar": "^1.6.0",
|
"chokidar": "^1.6.0",
|
||||||
"colors": "^1.1.2",
|
"colors": "^1.1.2",
|
||||||
|
|
|
@ -4,9 +4,11 @@
|
||||||
<!-- <link rel="stylesheet" href="css/app.css"> -->
|
<!-- <link rel="stylesheet" href="css/app.css"> -->
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js"></script>
|
||||||
<!-- <script src="js/bootstrap.js"></script> -->
|
<!-- <script src="js/bootstrap.js"></script> -->
|
||||||
<script src="js/app.js"></script>
|
|
||||||
</head>
|
</head>
|
||||||
<body class="container">
|
<body class="container">
|
||||||
|
|
||||||
|
<div id="root"></div>
|
||||||
|
|
||||||
<h3>Embark - Usage Example</h3>
|
<h3>Embark - Usage Example</h3>
|
||||||
|
|
||||||
<ul class="nav nav-tabs" role="tablist" id="myTabs">
|
<ul class="nav nav-tabs" role="tablist" id="myTabs">
|
||||||
|
@ -105,5 +107,6 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script src="js/app.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,20 +1,46 @@
|
||||||
/*globals $, SimpleStorage, document*/
|
/*globals $, SimpleStorage, document*/
|
||||||
|
|
||||||
|
//import React, { Component } from 'react';
|
||||||
|
import EmbarkJS from 'Embark/EmbarkJS';
|
||||||
|
import SimpleStorage from 'Embark/contracts/SimpleStorage';
|
||||||
|
import Test from 'Embark/contracts/Test';
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
let Component = React.Component;
|
||||||
|
|
||||||
|
import ReactDOM from 'react-dom';
|
||||||
|
|
||||||
//import $ from './_vendor/jquery.min';
|
//import $ from './_vendor/jquery.min';
|
||||||
import $ from 'jquery';
|
import $ from 'jquery';
|
||||||
import 'bootstrap';
|
import 'bootstrap';
|
||||||
import 'bootstrap/dist/css/bootstrap.min.css';
|
import 'bootstrap/dist/css/bootstrap.min.css';
|
||||||
//import 'bootstrap/dist/js/bootstrap.min.js';
|
//import 'bootstrap/dist/js/bootstrap.min.js';
|
||||||
import EmbarkJS from 'Embark/EmbarkJS';
|
|
||||||
import SimpleStorage from 'Embark/contracts/SimpleStorage';
|
|
||||||
import Test from 'Embark/contracts/Test';
|
|
||||||
|
|
||||||
window.EmbarkJS = EmbarkJS;
|
window.EmbarkJS = EmbarkJS;
|
||||||
window.SimpleStorage = SimpleStorage;
|
window.SimpleStorage = SimpleStorage;
|
||||||
window.Test = Test;
|
window.Test = Test;
|
||||||
|
|
||||||
|
window.React = React;
|
||||||
|
|
||||||
import './foo.css';
|
import './foo.css';
|
||||||
|
|
||||||
|
class App extends Component {
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div className="App">
|
||||||
|
<header className="App-header">
|
||||||
|
<h1 className="App-title">Welcome to React</h1>
|
||||||
|
</header>
|
||||||
|
<p className="App-intro">
|
||||||
|
To get started, edit <code>src/App.js</code> and save to reload.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ReactDOM.render(<App />, document.getElementById('root'));
|
||||||
|
|
||||||
var addToLog = function(id, txt) {
|
var addToLog = function(id, txt) {
|
||||||
$(id + " .logs").append("<br>" + txt);
|
$(id + " .logs").append("<br>" + txt);
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
"buildDir": "dist/",
|
"buildDir": "dist/",
|
||||||
"config": "config/",
|
"config": "config/",
|
||||||
"plugins": {
|
"plugins": {
|
||||||
"embark-babel": {"files": ["**/*.js", "**/*.jsx", "!**/_vendor/*.js"]},
|
|
||||||
"embark-service": {}
|
"embark-service": {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,9 @@
|
||||||
"devDependencies": {},
|
"devDependencies": {},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bootstrap": "^3.3.6",
|
"bootstrap": "^3.3.6",
|
||||||
"embark-babel": "^1.0.0",
|
|
||||||
"embark-service": "./extensions/embark-service",
|
"embark-service": "./extensions/embark-service",
|
||||||
"jquery": "^1.11.3"
|
"jquery": "^1.11.3",
|
||||||
|
"react": "^16.0.0",
|
||||||
|
"react-dom": "^16.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
{}
|
Loading…
Reference in New Issue