-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.cjs
78 lines (75 loc) · 2.34 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
const webpack = require('webpack');
const path = require('path');
const fs = require('fs');
const appDirectory = fs.realpathSync(process.cwd());
const resolveAppPath = relativePath => path.resolve(appDirectory, relativePath);
// webpack configuration V V V file from: https://digitalfortress.tech/debug/how-to-use-webpack-analyzer-bundle/
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const lastDirName = path.basename(__dirname);
const dropPath = path.join(__dirname, 'temp', 'stats');
// webpack configuration ^ ^ ^
module.exports = {
mode: 'development', // switch to production when you package for production - impacts final size of package you import
target: 'web',
entry: {
fpsJSFunctions: path.resolve(__dirname, 'src/indexes/index.ts') // myServices is the name of the library - external reference name: myServices.js
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: "[name].js", // [name] Comes from entry
publicPath: "/assets/",
library: { type: "amd" }, // Used by SPFx
clean: true
},
devtool: 'inline-source-map',
resolve: {
extensions: ['.ts', '.tsx', '.js'],
modules: ['node_modules']
},
module: {
rules: [{
test: /\.tsx|.ts?$/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader',
options: {
happyPackMode: true,
transpileOnly: true,
},
},
]
},
{
test: /\.svg/,
type: 'asset/resource'
}]
},
externals: { // Read webpack documentation - do not want to bundle these into the package
// "react": "React",
// "lodash-es": "lodash-es/*"
"@microsoft/sp-property-pane": "*",
"@microsoft/sp-webpart-base": "*",
},
devServer: {
compress: true,
hot: true,
port: 3000,
static: {
directory: resolveAppPath('app'),
publicPath: '/',
},
},
// webpack configuration V V V file from: https://digitalfortress.tech/debug/how-to-use-webpack-analyzer-bundle/
plugins: [
new BundleAnalyzerPlugin({
openAnalyzer: false,
analyzerMode: 'static',
reportFilename: path.join(dropPath, `${lastDirName}.stats.html`),
generateStatsFile: true,
statsFilename: path.join(dropPath, `${lastDirName}.stats.json`),
logLevel: 'error'
}),
]
// webpack configuration ^ ^ ^
};