2016-12-01 11:40:28 +02:00
|
|
|
/*
|
2020-01-06 16:48:55 +02:00
|
|
|
* Copyright © 2016-2019 The Thingsboard Authors
|
2016-12-01 11:40:28 +02:00
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
/* eslint-disable */
|
|
|
|
|
|
|
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
2019-07-19 19:17:51 +03:00
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
2016-12-01 11:40:28 +02:00
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
2018-07-06 20:49:19 +03:00
|
|
|
const CompressionPlugin = require('compression-webpack-plugin');
|
2019-07-19 19:17:51 +03:00
|
|
|
|
2016-12-01 11:40:28 +02:00
|
|
|
const webpack = require('webpack');
|
|
|
|
|
const path = require('path');
|
2018-07-14 21:19:23 +05:00
|
|
|
const dirTree = require('directory-tree');
|
2018-07-17 17:33:55 +05:00
|
|
|
const jsonminify = require("jsonminify");
|
2016-12-01 11:40:28 +02:00
|
|
|
|
2018-07-07 20:26:33 +05:00
|
|
|
const PUBLIC_RESOURCE_PATH = '/static/';
|
|
|
|
|
|
2018-07-14 21:19:23 +05:00
|
|
|
var langs = [];
|
|
|
|
|
dirTree('./src/app/locale/', {extensions:/\.json$/}, (item) => {
|
|
|
|
|
/* It is expected what the name of a locale file has the following format: */
|
|
|
|
|
/* 'locale.constant-LANG_CODE[_REGION_CODE].json', e.g. locale.constant-es.json or locale.constant-zh_CN.json*/
|
|
|
|
|
langs.push(item.name.slice(item.name.lastIndexOf('-') + 1, -5));
|
|
|
|
|
});
|
|
|
|
|
|
2016-12-01 11:40:28 +02:00
|
|
|
module.exports = {
|
2019-07-19 19:17:51 +03:00
|
|
|
mode: 'production',
|
2017-02-22 21:34:28 +02:00
|
|
|
entry: [
|
|
|
|
|
'./src/app/app.js',
|
|
|
|
|
'webpack-material-design-icons'
|
|
|
|
|
],
|
2016-12-01 11:40:28 +02:00
|
|
|
output: {
|
|
|
|
|
path: path.resolve(__dirname, 'target/generated-resources/public/static'),
|
2018-07-07 20:26:33 +05:00
|
|
|
publicPath: PUBLIC_RESOURCE_PATH,
|
2016-12-01 11:40:28 +02:00
|
|
|
filename: 'bundle.[hash].js',
|
2019-07-23 18:31:52 +03:00
|
|
|
pathinfo: false
|
2016-12-01 11:40:28 +02:00
|
|
|
},
|
|
|
|
|
plugins: [
|
|
|
|
|
new webpack.ProvidePlugin({
|
|
|
|
|
$: "jquery",
|
|
|
|
|
jQuery: "jquery",
|
|
|
|
|
"window.jQuery": "jquery",
|
|
|
|
|
tinycolor: "tinycolor2",
|
|
|
|
|
tv4: "tv4",
|
|
|
|
|
moment: "moment"
|
|
|
|
|
}),
|
|
|
|
|
new CopyWebpackPlugin([
|
2018-07-17 17:33:55 +05:00
|
|
|
{
|
|
|
|
|
from: './src/thingsboard.ico',
|
|
|
|
|
to: 'thingsboard.ico'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
from: './src/app/locale',
|
|
|
|
|
to: 'locale',
|
|
|
|
|
ignore: [ '*.js' ],
|
|
|
|
|
transform: function(content, path) {
|
|
|
|
|
return Buffer.from(jsonminify(content.toString()));
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-01 11:40:28 +02:00
|
|
|
]),
|
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
|
template: './src/index.html',
|
|
|
|
|
filename: '../index.html',
|
2017-08-30 20:41:20 +03:00
|
|
|
title: 'ThingsBoard',
|
2016-12-01 11:40:28 +02:00
|
|
|
inject: 'body',
|
|
|
|
|
}),
|
2019-07-19 19:17:51 +03:00
|
|
|
new MiniCssExtractPlugin({
|
|
|
|
|
filename: 'style.[contentHash].css'
|
2016-12-01 11:40:28 +02:00
|
|
|
}),
|
|
|
|
|
new webpack.DefinePlugin({
|
2017-05-03 14:24:26 +03:00
|
|
|
THINGSBOARD_VERSION: JSON.stringify(require('./package.json').version),
|
2016-12-01 11:40:28 +02:00
|
|
|
'__DEVTOOLS__': false,
|
2018-07-14 21:19:23 +05:00
|
|
|
PUBLIC_PATH: PUBLIC_RESOURCE_PATH,
|
|
|
|
|
SUPPORTED_LANGS: JSON.stringify(langs)
|
2016-12-01 11:40:28 +02:00
|
|
|
}),
|
2018-07-06 20:49:19 +03:00
|
|
|
new CompressionPlugin({
|
2019-07-19 19:17:51 +03:00
|
|
|
filename: "[path].gz[query]",
|
2018-07-06 20:49:19 +03:00
|
|
|
algorithm: "gzip",
|
2019-02-06 15:32:54 +00:00
|
|
|
test: /\.js$|\.css$|\.svg$|\.ttf$|\.woff$|\.woff2$|\.eot$|\.json$/,
|
2018-07-06 20:49:19 +03:00
|
|
|
threshold: 10240,
|
|
|
|
|
minRatio: 0.8
|
|
|
|
|
})
|
2016-12-01 11:40:28 +02:00
|
|
|
],
|
|
|
|
|
node: {
|
|
|
|
|
tls: "empty",
|
|
|
|
|
fs: "empty"
|
|
|
|
|
},
|
|
|
|
|
module: {
|
2019-07-19 19:17:51 +03:00
|
|
|
rules: [
|
2016-12-01 11:40:28 +02:00
|
|
|
{
|
|
|
|
|
test: /\.jsx$/,
|
2019-07-19 19:17:51 +03:00
|
|
|
use: [
|
|
|
|
|
{
|
|
|
|
|
loader: 'babel-loader',
|
|
|
|
|
options: {
|
|
|
|
|
cacheDirectory: true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
],
|
2016-12-01 11:40:28 +02:00
|
|
|
exclude: /node_modules/,
|
|
|
|
|
include: __dirname,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.js$/,
|
2019-07-19 19:17:51 +03:00
|
|
|
use: [
|
|
|
|
|
{
|
|
|
|
|
loader: 'ng-annotate-loader',
|
|
|
|
|
options: {
|
|
|
|
|
ngAnnotate: 'ng-annotate-patched',
|
|
|
|
|
es6: true,
|
|
|
|
|
explicitOnly: false
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
loader: 'babel-loader',
|
|
|
|
|
options: {
|
|
|
|
|
cacheDirectory: true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
],
|
2016-12-01 11:40:28 +02:00
|
|
|
exclude: /node_modules/,
|
|
|
|
|
include: __dirname,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.js$/,
|
2019-07-19 19:17:51 +03:00
|
|
|
use: [
|
|
|
|
|
{
|
|
|
|
|
loader: 'eslint-loader',
|
|
|
|
|
options: {
|
|
|
|
|
parser: 'babel-eslint'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
],
|
2016-12-01 11:40:28 +02:00
|
|
|
exclude: /node_modules|vendor/,
|
|
|
|
|
include: __dirname,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.css$/,
|
2019-07-19 19:17:51 +03:00
|
|
|
use: [
|
|
|
|
|
MiniCssExtractPlugin.loader,
|
|
|
|
|
'css-loader'
|
|
|
|
|
]
|
2016-12-01 11:40:28 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.scss$/,
|
2019-07-19 19:17:51 +03:00
|
|
|
use: [
|
|
|
|
|
MiniCssExtractPlugin.loader,
|
|
|
|
|
'css-loader',
|
|
|
|
|
'postcss-loader',
|
|
|
|
|
'sass-loader'
|
|
|
|
|
]
|
2016-12-01 11:40:28 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.less$/,
|
2019-07-19 19:17:51 +03:00
|
|
|
use: [
|
|
|
|
|
MiniCssExtractPlugin.loader,
|
|
|
|
|
'css-loader',
|
|
|
|
|
'postcss-loader',
|
|
|
|
|
'less-loader'
|
|
|
|
|
]
|
2016-12-01 11:40:28 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.tpl\.html$/,
|
2019-07-19 19:17:51 +03:00
|
|
|
use: [
|
|
|
|
|
{
|
|
|
|
|
loader: 'ngtemplate-loader',
|
|
|
|
|
options: {
|
|
|
|
|
relativeTo: path.resolve(__dirname, './src/app')
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
loader: 'html-loader'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
loader: 'html-minifier-loader',
|
|
|
|
|
options: {
|
|
|
|
|
caseSensitive: true,
|
|
|
|
|
removeComments: true,
|
|
|
|
|
collapseWhitespace: false,
|
|
|
|
|
preventAttributesEscaping: true,
|
|
|
|
|
removeEmptyAttributes: false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
2016-12-01 11:40:28 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.(svg)(\?v=[0-9]+\.[0-9]+\.[0-9]+)?$/,
|
2019-07-19 19:17:51 +03:00
|
|
|
use: [
|
|
|
|
|
{
|
|
|
|
|
loader: 'url-loader',
|
|
|
|
|
options: {
|
|
|
|
|
limit: 8192
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
2016-12-01 11:40:28 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.(png|jpe?g|gif|woff|woff2|ttf|otf|eot|ico)(\?v=[0-9]+\.[0-9]+\.[0-9]+)?$/,
|
2019-07-19 19:17:51 +03:00
|
|
|
use: [
|
|
|
|
|
{
|
|
|
|
|
loader: 'url-loader',
|
|
|
|
|
options: {
|
|
|
|
|
limit: 8192
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
loader: 'img-loader',
|
|
|
|
|
options: {
|
|
|
|
|
minimize: true
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-01 11:40:28 +02:00
|
|
|
]
|
2018-07-07 20:26:33 +05:00
|
|
|
}
|
2016-12-01 11:40:28 +02:00
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
};
|