forked from HadoukenIO/notifications-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
150 lines (143 loc) · 4.63 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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
/**
* creates a webpack config for the UI (provider UI aka notification center)
* @param {string} projectPath The path to the project
* @param {string} entryPoint The entry point to the application,
* usually a js file
* @return {Object} A webpack module for the project
*/
function createWebpackConfigForProviderUI(entryPoint) {
return Object.assign({
entry: entryPoint,
output: {
path: path.resolve(__dirname, './build/ui/pack'),
filename: '[name]-bundle.js'
},
resolve: {
extensions: ['.ts', '.tsx', '.js']
},
devtool:'source-map',
module: {
rules: [
{
test: /\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader
},
"css-loader"
]
},
{
test: /\.(png|jpg|gif|otf|svg)$/,
use: [
{
loader: 'url-loader',
options: {
limit: 8192
}
}
]
},
{
test: /\.tsx?$/,
loader: 'ts-loader'
}
]
},
plugins: [
new MiniCssExtractPlugin({ filename: 'bundle.css' }),
new CopyWebpackPlugin([
{ from: './src/ui', to: '..', ignore: ["**/*.ts", "**/*.tsx"] }
])
]
});
}
function createWebpackConfigForProvider() {
return {
entry: './staging/src/provider/index.js',
output: {
path: path.resolve(__dirname, './build'),
filename: 'provider.js'
},
devtool:'source-map',
plugins: [
new CopyWebpackPlugin([
{ from: './src/provider.html' }
]),
new CopyWebpackPlugin([
{ from: './src/app.template.json', to: 'app.json', transform: (content) => {
const config = JSON.parse(content);
const newConfig = prepConfig(config, 'http://localhost:9048/provider.html');
return JSON.stringify(newConfig, null, 4);
}}
])
]
}
}
function createWebpackConfigForDemo(entryPoint) {
return {
entry: entryPoint,
output: {
path: path.resolve(__dirname, './build/demo'),
filename: '[name].js'
},
resolve: {
extensions: ['.ts']
},
devtool:'source-map',
module: {
rules: [
{
test: /\.ts$/,
loader: 'ts-loader'
}
]
},
plugins: [
new CopyWebpackPlugin([
{ from: './src/demo/app-launcher.html'},
{ from: './src/demo/app.css'},
{ from: './src/demo/app.html'}
]),
new CopyWebpackPlugin([
{
from: './src/demo/app-launcher.json',
transform: (content) => {
const config = JSON.parse(content);
const newConfig = prepConfig(config, 'http://localhost:9048/demo/app-launcher.html');
return JSON.stringify(newConfig, null, 4);
}
}
])
]
};
}
function prepConfig(config, defaultUrl) {
const newConf = Object.assign({}, config);
if (typeof process.env.SERVICE_VERSION != 'undefined' && process.env.SERVICE_VERSION != "" ) {
newConf.startup_app.url = 'https://cdn.openfin.co/services/openfin/notifications/' + process.env.SERVICE_VERSION + '/provider.html';
newConf.startup_app.autoShow = false;
} else if (typeof defaultUrl != 'undefined' && defaultUrl != "" ) {
newConf.startup_app.url = defaultUrl;
}
return newConf;
}
/**
* Modules to be exported
*/
module.exports = [
createWebpackConfigForProvider(),
createWebpackConfigForProviderUI({
react: './src/ui/js/index.tsx',
serviceui: './src/ui/index.ts',
openfin: './src/ui/js/openfin.ts',
toast: './src/ui/js/toast/index.tsx'
}),
createWebpackConfigForDemo({
app: './src/demo/app.ts',
'app-launcher': './src/demo/app-launcher.ts'
}),
];