Skip to content

Commit

Permalink
[update] app/module config
Browse files Browse the repository at this point in the history
  • Loading branch information
mkozhukh committed Apr 22, 2018
1 parent 4530428 commit b99b16a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 17 deletions.
7 changes: 4 additions & 3 deletions .babelrc
Expand Up @@ -4,8 +4,9 @@
"targets": {
"browsers": ["last 2 versions", "IE >= 11"]
},
modules:false,
loose:true
"modules":false,
"loose":true
}]
]
],
"plugins": ["transform-object-rest-spread"]
}
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -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": [
Expand All @@ -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",
Expand All @@ -29,6 +32,6 @@
"webpack-dev-server": "^2.8.2"
},
"dependencies": {
"webix-jet": "^1.4.0"
"webix-jet": "^1.5.0"
}
}
29 changes: 17 additions & 12 deletions 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);
});
});
super({ ...defaults, ...config });
}
}

if (!BUILD_AS_MODULE){
webix.ready(() => new MyApp().render() );
}
22 changes: 21 additions & 1 deletion webpack.config.js
Expand Up @@ -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')
};
Expand Down Expand Up @@ -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)
})
]
};
Expand All @@ -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;
}

0 comments on commit b99b16a

Please sign in to comment.