forked from telerik/kendo-theme-default
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
71 lines (64 loc) · 1.99 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"use strict";
/*
* Build CSS out of SCSS files using webpack, reusing the
* configuration already in place for react / ng2 components.
* This script creates a webpack entry for each of the packages,
* and passes it through the kendo-common-tasks theme config.
*/
const glob = require('glob');
const path = require('path');
const fs = require('fs');
const port = parseInt(process.env.PORT || 3000);
const devServerPort = port + 1;
/*
* Webpack plug-in that reloads css via browser-sync upon build
*/
function BrowserSync() {
this.bs = require("browser-sync").create('bs-refresh');
this.bs.init({
open: false,
proxy: `http://localhost:${devServerPort}/`,
port: port,
host: '0.0.0.0'
});
}
BrowserSync.prototype = {
apply: function(compiler) {
compiler.plugin("emit", (compilation, callback) => {
this.bs.reload("dist.css");
callback();
});
}
};
let entry = { 'all': './build/all.js' };
const components = process.env.COMPONENTS || null;
if (components) {
// custom build
const fs = require('fs');
const path = require('path');
const imports = components.split(',')
.map(c => `require("./../scss/${c}.scss");`).join('\n')
fs.writeFileSync(path.join('build', 'custom.js'), imports);
entry = { 'custom': './build/custom.js' };
}
const compat = process.argv.indexOf('--env.twbs-compat') > -1;
if (compat) {
entry = { 'twbs-compat': './build/twbs-compat.js' };
}
const inDevelopment = process.argv.find(v => v.includes('webpack-dev-server'))
module.exports = require('@telerik/kendo-common-tasks')
.webpackThemeConfig({ extract: true }, {
devServer: {
hot: true,
inline: true,
port: devServerPort
},
module: { loaders: [] },
entry: entry,
plugins: inDevelopment ? [ new BrowserSync() ] : [],
output: {
path: 'dist',
publicPath: '/dist/',
filename: '[name].js'
}
});