diff --git a/.babelrc b/.babelrc index 75d8219a..ef3fed1c 100644 --- a/.babelrc +++ b/.babelrc @@ -4,8 +4,9 @@ "targets": { "browsers": ["last 2 versions", "IE >= 11"] }, - modules:false, - loose:true + "modules":false, + "loose":true }] - ] + ], + "plugins": ["transform-object-rest-spread"] } \ No newline at end of file diff --git a/package.json b/package.json index eab306f2..ef4dab2a 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,8 @@ "test": "echo \"Error: no test specified\" && exit 1", "lint": "eslint sources/", "build": "webpack --env.production true", + "module": "webpack --env.production true --env.module true", + "standalone": "webpack --env.production true --env.module true --env.standalone true", "start": "webpack-dev-server" }, "keywords": [ @@ -18,6 +20,7 @@ "babel-core": "^6.26.0", "babel-loader": "^7.1.2", "babel-preset-env": "^1.6.0", + "babel-plugin-transform-object-rest-spread": "^6.26.0", "css-loader": "^0.28.7", "eslint": "^4.7.2", "extract-text-webpack-plugin": "^3.0.0", @@ -29,6 +32,6 @@ "webpack-dev-server": "^2.8.2" }, "dependencies": { - "webix-jet": "^1.4.0" + "webix-jet": "^1.5.0" } } diff --git a/sources/myapp.js b/sources/myapp.js index 7b8a85d5..0fb6c0b9 100644 --- a/sources/myapp.js +++ b/sources/myapp.js @@ -1,15 +1,20 @@ import "./styles/app.css"; -import {JetApp} from "webix-jet"; +import {JetApp, EmptyRouter, HashRouter } from "webix-jet"; -webix.ready(() => { - var app = new JetApp({ - id: APPNAME, - version: VERSION, - start: "/top/start" - }); - app.render(); +export default class MyApp extends JetApp{ + constructor(config){ + const defaults = { + id : APPNAME, + version : VERSION, + router : BUILD_AS_MODULE ? EmptyRouter : HashRouter, + debug : !PRODUCTION, + start : "/top/start" + }; - app.attachEvent("app:error:resolve", function(name, error){ - window.console.error(error); - }); -}); \ No newline at end of file + super({ ...defaults, ...config }); + } +} + +if (!BUILD_AS_MODULE){ + webix.ready(() => new MyApp().render() ); +} \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index 20a6ef8c..0503c246 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -5,7 +5,11 @@ module.exports = function(env) { var pack = require("./package.json"); var ExtractTextPlugin = require("extract-text-webpack-plugin"); + var production = !!(env && env.production === "true"); + var asmodule = !!(env && env.module === "true"); + var standalone = !!(env && env.standalone === "true"); + var babelSettings = { extends: path.join(__dirname, '/.babelrc') }; @@ -47,7 +51,8 @@ module.exports = function(env) { new webpack.DefinePlugin({ VERSION: `"${pack.version}"`, APPNAME: `"${pack.name}"`, - PRODUCTION : production + PRODUCTION : production, + BUILD_AS_MODULE : (asmodule || standalone) }) ] }; @@ -60,5 +65,20 @@ module.exports = function(env) { ); } + if (asmodule){ + if (!standalone){ + config.externals = config.externals || {}; + config.externals = [ "webix-jet" ]; + } + + const out = config.output; + const sub = standalone ? "full" : "module"; + + out.library = pack.name.replace(/[^a-z0-9]/gi, ""); + out.libraryTarget= "umd"; + out.path = path.join(__dirname, "dist", sub); + out.publicPath = "/dist/"+sub+"/"; + } + return config; } \ No newline at end of file