This repository has been archived by the owner on Apr 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.base.js
122 lines (115 loc) · 3.76 KB
/
webpack.base.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var fs = require('fs');
var et = require('elementtree');
var execSync = require('child_process').execSync;
/*
* These functions extract the version number and git commit number
* to create a unique version number that is embedded in the APP
* as X.Y.Z.`git rev-list --count HEAD`.
*/
function parseElementtreeSync(filename) {
var contents = fs.readFileSync(filename, 'utf-8');
if (contents) {
//Windows is the BOM. Skip the Byte Order Mark.
contents = contents.substring(contents.indexOf('<'));
}
return new et.ElementTree(et.XML(contents));
}
function getSemanticVersion() {
let xml = parseElementtreeSync(path.join(__dirname, 'config.xml'));
let widget = xml.getroot();
let version = widget.get("version");
return version;
}
function getVersion() {
let version = getSemanticVersion();
let commitCount = execSync('git rev-list --count HEAD');
return version + "." + commitCount.toString().trim();
}
let version = '"' + getVersion() + '"';
let semVer = '"' + getSemanticVersion() + '"';
module.exports = {
entry: {
app: [
'./app/app.ts'
]
},
output: {
filename: '[name].js',
path: path.join(__dirname, "www/"),
sourceMapFilename: '[name].map'
},
module: {
rules: [{
test: /\.tsx?$/,
use: [{
loader: 'ts-loader'
}],
exclude: /node_modules/,
},
{
test: /\.css$/,
use: [{
loader: "style-loader" // creates style nodes from JS strings
}, {
loader: "css-loader" // translates CSS into CommonJS
}]
},
{
test: /\.scss$/,
use: [{
loader: "style-loader" // creates style nodes from JS strings
}, {
loader: "css-loader" // translates CSS into CommonJS
}, {
loader: "sass-loader", // compiles Sass to CSS
options: {
includePaths: [path.resolve(__dirname, "./node_modules")]
}
}]
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: "url-loader?limit=10000&mimetype=application/font-woff"
},
{
test: /\.(ttf|eot|svg|png)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: "file-loader"
}
]
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: 'vendor.js',
minChunks(module, count) {
var context = module.context;
return context && context.indexOf('node_modules') >= 0;
},
}),
new HtmlWebpackPlugin({
template: 'app/index.html',
inject: false
}),
new CopyWebpackPlugin([{
from: "main/**/*.html",
context: "app"
}]),
new webpack.DefinePlugin({
IOTILE_VERSION_AND_BUILD: version,
IOTILE_VERSION: semVer
})
],
resolve: {
extensions: [".tsx", ".ts", ".js", ".json"],
modules: ['app/packages', 'node_modules'],
alias: {
'typescript-logging': path.resolve('./node_modules/typescript-logging'),
'msgpack-lite': path.resolve('./node_modules/msgpack-lite'),
'@iotile/iotile-common': path.resolve('./node_modules/@iotile/iotile-common')
}
}
};