-
Notifications
You must be signed in to change notification settings - Fork 6
/
webpack.react.js
119 lines (104 loc) · 2.91 KB
/
webpack.react.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
const HtmlWebPackPlugin = require("html-webpack-plugin");
let MiniCssExtractPlugin = require('mini-css-extract-plugin');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const LicenseCheckerWebpackPlugin = require("license-checker-webpack-plugin");
const path = require('path');
const distPath = path.resolve(__dirname, '../homey-heating-dist');
const version = require("./package.json").version;
var scriptConfig = (env, argv) => {
const PRODUCTION = argv.mode === 'production';
const plugins = [
new webpack.DefinePlugin({
__PRODUCTION__: JSON.stringify(argv.mode === 'production'),
__HOMEY_DEV_URL: JSON.stringify(process.env.HOMEY_DEV_URL || "http://192.168.178.117"),
__VERSION: JSON.stringify(version),
__HOMEY_LANG: JSON.stringify(process.env.HOMEY_LANG || "en"),
__BUILD: JSON.stringify(process.env.TRAVIS_BUILD_NUMBER),
}),
new MiniCssExtractPlugin({
filename: "[name].css",
chunkFilename: "[id].css"
}),
];
if (!PRODUCTION) {
plugins.push(
new HtmlWebPackPlugin({
template: "./index.dev.html",
filename: "./index.html",
}));
}
else {
plugins.push(new webpack.SourceMapDevToolPlugin({
filename: '[file].map',
publicPath: `https://raw.githubusercontent.com/mskg/homey-heating/release/v${version}/settings/`
}));
plugins.push(
new CopyWebpackPlugin([{
from: './index.prod.html',
to: distPath + "/settings/index.html"
}]));
}
if (PRODUCTION) {
plugins.push(
new LicenseCheckerWebpackPlugin({
allow: "(GPL-3.0 OR Apache-2.0 OR BSD-2-Clause OR BSD-3-Clause OR MIT)",
outputFilename: "ThirdPartyNotices.txt",
emitError: true,
override: {
"[email protected]": { licenseName: "MIT" },
}
}));
}
return {
context: path.join(__dirname, 'src/settings'),
entry: {
app: './index.tsx',
},
devtool: PRODUCTION ? false : 'inline-source-map',
resolve: {
extensions: [".ts", ".tsx", ".js", ".json"],
alias: {
"react": path.join(__dirname, "./node_modules/react")
},
},
externals: ["Homey"],
optimization: {
splitChunks: {
// include all types of chunks
chunks: 'all'
}
},
module: {
rules: [{
test: /\.tsx?$/,
loader: "ts-loader"
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader, "css-loader"
],
},
{
test: /\.(png|jpg|gif|svg)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]',
esModule: false,
},
},
],
}
]
},
plugins: plugins,
output: {
filename: "[name].js",
path: distPath + "/settings"
},
};
};
module.exports = scriptConfig;