-
Notifications
You must be signed in to change notification settings - Fork 198
/
webpack.config.cjs
112 lines (106 loc) · 3.24 KB
/
webpack.config.cjs
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
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable no-undef */
const TerserPlugin = require('terser-webpack-plugin');
const { SubresourceIntegrityPlugin } = require('webpack-subresource-integrity');
const { readFileSync } = require('fs');
const { join } = require('path');
const WebpackAssetsManifest = require('webpack-assets-manifest');
const libraryName = 'microsoftTeams';
const { expect } = require('expect');
const path = require('path');
const { DefinePlugin } = require('webpack');
const packageVersion = require('./package.json').version;
const FileManagerPlugin = require('filemanager-webpack-plugin');
const { ProvidePlugin } = require('webpack');
module.exports = {
entry: {
MicrosoftTeams: './src/index.ts',
'MicrosoftTeams.min': './src/index.ts',
},
output: {
filename: '[name].js',
// the following setting is required for SRI to work
crossOriginLoading: 'anonymous',
path: path.resolve(__dirname, 'dist/umd'),
library: {
name: libraryName,
type: 'umd',
umdNamedDefine: true,
},
//Typically resolves to 'self' unless running in a server side rendered environment
globalObject: "typeof self !== 'undefined' ? self : this",
},
devtool: 'source-map',
resolve: {
extensions: ['.tsx', '.ts', '.js'],
fallback: {
buffer: require.resolve('skeleton-buffer/'),
},
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
reduce_funcs: false,
inline: false,
},
},
include: /\.min\.js$/,
}),
],
nodeEnv: 'production',
},
// webpack.production.config.js
mode: 'production',
performance: {
hints: false,
},
plugins: [
new DefinePlugin({
PACKAGE_VERSION: JSON.stringify(packageVersion),
}),
// https://www.npmjs.com/package/webpack-subresource-integrity
new SubresourceIntegrityPlugin({ enabled: true }),
new ProvidePlugin({
Buffer: ['skeleton-buffer', 'Buffer'],
}),
// Webpackmanifest produces the json file containing asset(JS file) and its corresponding hash values(Example: https://github.com/waysact/webpack-subresource-integrity/blob/main/examples/webpack-assets-manifest/webpack.config.js)
new WebpackAssetsManifest({
integrity: true,
integrityHashes: ['sha384'],
output: 'MicrosoftTeams-manifest.json',
}),
{
apply: (compiler) => {
compiler.hooks.done.tap('wsi-test', () => {
const manifest = JSON.parse(readFileSync(join(__dirname, 'dist/umd/MicrosoftTeams-manifest.json'), 'utf-8'));
// If for some reason hash was not generated for the assets, this test will fail in build.
expect(manifest['MicrosoftTeams.min.js'].integrity).toMatch(/sha384-.*/);
});
},
},
new FileManagerPlugin({
events: {
onEnd: {
copy: [
{
source: './dist/umd/MicrosoftTeams.min.js',
destination: '../../apps/blazor-test-app/wwwroot/js/MicrosoftTeams.min.js',
},
],
},
},
}),
],
};