-
Notifications
You must be signed in to change notification settings - Fork 14
/
widget.webpack.js
88 lines (84 loc) · 2.66 KB
/
widget.webpack.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
/* eslint-env node */
const fs = require('fs');
const path = require('path');
const autoprefixer = require('autoprefixer');
const TerserPlugin = require('terser-webpack-plugin');
const SRC_PATH = path.resolve('src');
const NODE_MODULES_PATH = path.resolve('node_modules');
const WIDGET_SRC_PATH = path.resolve(SRC_PATH, 'widget');
const WIDGET_RESULT_PATH = path.resolve(__dirname, 'widget');
const WIDGET_BUNDLE_FILENAME = 'index.js';
module.exports = {
entry: {
index: path.resolve(WIDGET_SRC_PATH, 'index.tsx'),
},
output: {
path: WIDGET_RESULT_PATH,
filename: WIDGET_BUNDLE_FILENAME,
},
mode: 'production',
module: {
rules: [
{
test: /\.[jt]sx?$/,
exclude: [/node_modules/],
use: {
loader: 'babel-loader',
},
},
{
test: /\.(scss|css)$/,
include: [
path.resolve(NODE_MODULES_PATH, '@diplodoc/transform'),
path.resolve(NODE_MODULES_PATH, '@gravity-ui/components'),
path.resolve(NODE_MODULES_PATH, '@gravity-ui/uikit'),
path.resolve(NODE_MODULES_PATH, 'swiper'),
path.resolve(__dirname, 'styles'),
SRC_PATH,
],
use: [
'style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
postcssOptions: {plugins: [autoprefixer()]},
},
},
'resolve-url-loader',
'sass-loader',
],
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
plugins: [
{
apply: (compiler) => {
compiler.hooks.assetEmitted.tap('InjectWidgetBundlePlugin', (_, {content}) => {
const script = JSON.stringify(content.toString());
const fileContent = `export default ${script};`;
fs.writeFileSync(
path.resolve(WIDGET_RESULT_PATH, WIDGET_BUNDLE_FILENAME),
fileContent,
);
});
},
},
],
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: false,
terserOptions: {
format: {
comments: false,
},
},
}),
],
},
};