diff --git a/lib/pipeline/pipeline.js b/lib/pipeline/pipeline.js index 8adc375a4..95626c7a2 100644 --- a/lib/pipeline/pipeline.js +++ b/lib/pipeline/pipeline.js @@ -7,6 +7,11 @@ var utils = require('../utils/utils.js'); //let currentWeb3Version = require('../../package.json').dependencies.web3.replace("^",""); const webpack = require("webpack"); +require("babel-preset-react"); +require("babel-preset-es2015"); +require("babel-preset-es2016"); +require("babel-preset-es2017"); + class Pipeline { constructor(options) { @@ -57,6 +62,42 @@ class Pipeline { 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) { + 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) { if (request === utils.joinPath(fs.dappPath(), file.filename)) { callback(); @@ -70,16 +111,38 @@ class Pipeline { } 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) => { next(); }); - }, - function changeCwd(next) { - realCwd = process.env.PWD; - process.chdir(fs.embarkPath('')); - next(); }, function runWebpack(next) { @@ -117,9 +180,20 @@ class Pipeline { { 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) => { next(); }); @@ -192,16 +266,16 @@ class Pipeline { } buildContracts(contractsJSON) { - fs.mkdirpSync(this.buildDir + 'contracts'); + fs.mkdirpSync(utils.joinPath(fs.dappPath(), this.buildDir, 'contracts')); for (let className in contractsJSON) { 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) { - 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 = ""; contractCode += "import web3 from 'Embark/web3';\n"; diff --git a/package.json b/package.json index b857e88cf..9de8bab93 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,13 @@ }, "dependencies": { "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", "chokidar": "^1.6.0", "colors": "^1.1.2", diff --git a/test_app/app/index.html b/test_app/app/index.html index 80a00fa23..9ee0951ea 100644 --- a/test_app/app/index.html +++ b/test_app/app/index.html @@ -4,9 +4,11 @@ - + +
+

Embark - Usage Example