]> git.localhorst.tv Git - gtbkgg-extension.git/blob - webpack.config.js
v0.0.1
[gtbkgg-extension.git] / webpack.config.js
1 const fs = require('fs')
2 const path = require("path")
3 const webpack = require("webpack")
4 const HtmlWebpackPlugin = require('html-webpack-plugin')
5
6 // defines where the bundle file will live
7 const bundlePath = path.resolve(__dirname, "dist/")
8
9 module.exports = (_env,argv)=> {
10         let entryPoints = {
11                 VideoComponent:{
12                         path:"./src/VideoComponent.js",
13                         outputHtml:"video_component.html",
14                         build:false
15                 },
16                 VideoOverlay:{
17                         path:"./src/VideoOverlay.js",
18                         outputHtml:"video_overlay.html",
19                         build:false
20                 },
21                 Panel:{
22                         path:"./src/Panel.js",
23                         outputHtml:"panel.html",
24                         build:true
25                 },
26                 Config:{
27                         path:"./src/Config.js",
28                         outputHtml:"config.html",
29                         build:false
30                 },
31                 LiveConfig:{
32                         path:"./src/LiveConfig.js",
33                         outputHtml:"live_config.html",
34                         build:false
35                 },
36                 Mobile:{
37                         path:"./src/Mobile.js",
38                         outputHtml:"mobile.html",
39                         build:false
40                 }
41         }
42
43         let entry = {}
44
45         // edit webpack plugins here!
46         let plugins = [
47         ]
48
49         for(name in entryPoints){
50                 if(entryPoints[name].build){
51                         entry[name]=entryPoints[name].path
52                         if(argv.mode==='production'){
53                                 plugins.push(new HtmlWebpackPlugin({
54                                         inject:true,
55                                         chunks:[name],
56                                         template:'./template.html',
57                                         filename:entryPoints[name].outputHtml
58                                 }))
59                         }
60                 }               
61         }
62
63         let config={
64                 //entry points for webpack- remove if not used/needed
65                 entry,
66                 optimization: {
67                         minimize: false // neccessary to pass Twitch's review process
68                 },
69                 module: {
70                         rules: [
71                                 {
72                                         test: /\.(js|jsx)$/,
73                                         exclude: /(node_modules|bower_components)/,
74                                         loader: 'babel-loader',
75                                         options: { presets: ['@babel/preset-env'] }
76                                 },
77                                 {
78                                         test: /\.css$/,
79                                         use: [ 'style-loader', 'css-loader' ]
80                                 },
81                                 {
82                                         test: /\.(jpe?g|png|gif|svg)$/i, 
83                                         loader: "file-loader",
84                                         options:{
85                                                 name:"img/[name].[ext]"
86                                         }
87                                 }
88                         ]
89                 },
90                 resolve: { extensions: ['*', '.js', '.jsx'] },
91                 output: {
92                         filename: "[name].bundle.js",
93                         path:bundlePath
94                 },
95                 plugins
96         }
97         if(argv.mode==='development'){
98                 config.devServer = {
99                         allowedHosts: ['all'],
100                         host:argv.devrig ? 'localhost.rig.twitch.tv' : 'local-ip',
101                         headers: {
102                                 'Access-Control-Allow-Origin': '*'
103                         },
104                         port: 8080
105                 }
106                 if(fs.existsSync(path.resolve(__dirname,'conf/server.key'))){
107                         config.devServer.server = {
108                                 type: 'https',
109                                 options: {
110                                         key:fs.readFileSync(path.resolve(__dirname,'conf/server.key')),
111                                         cert:fs.readFileSync(path.resolve(__dirname,'conf/server.crt'))
112                                 }
113                         }
114                 }
115         }
116
117         return config;
118 }