-
Notifications
You must be signed in to change notification settings - Fork 9
/
webpack.config.js
104 lines (102 loc) · 2.59 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
const CreateFileWebpack = require('create-file-webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
const webpack = require('webpack');
const { figmaPlugin } = require('./package.json');
module.exports = (env, argv) => ({
mode: argv.mode === 'production' ? 'production' : 'development',
devtool: argv.mode === 'production' ? false : 'inline-source-map',
devServer: {
https: true,
},
optimization: {
minimize: argv.mode === 'production',
minimizer:
argv.mode === 'production'
? [
new TerserPlugin({
terserOptions: {
mangle: true,
},
}),
]
: [],
},
entry: {
ui: './src/App.tsx',
code: './src/main/index.ts',
},
watchOptions: {
ignored: ['node_modules/**'],
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'esbuild-loader',
options: {
loader: 'tsx', // Or 'ts' if you don't need tsx
target: 'es2015',
},
},
{
test: /\.css$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
},
],
},
{
test: /\.(png|jpg|gif|webp|svg|zip|mp3)$/,
loader: 'url-loader',
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.jsx', '.js'],
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, figmaPlugin.name.replace(/\s/g, '-')),
},
plugins: [
new HtmlWebpackPlugin({
filename: 'ui.html',
inlineSource: '.(js)$',
chunks: ['ui'],
inject: false,
templateContent: ({ compilation, htmlWebpackPlugin }) => `
<html>
<body>
<div id="app"></div>
${htmlWebpackPlugin.files.js.map(
(jsFile) =>
`<script>${compilation.assets[
jsFile.substr(htmlWebpackPlugin.files.publicPath.length)
].source()}</script>`,
)}
</body>
</html>
`,
}),
new webpack.DefinePlugin({
process: {
env: {
REACT_APP_SC_ATTR: JSON.stringify('data-styled-figma-measure'),
SC_ATTR: JSON.stringify('data-styled-figma-measure'),
REACT_APP_SC_DISABLE_SPEEDY: JSON.stringify('false'),
},
},
}),
new CreateFileWebpack({
path: path.resolve(__dirname, figmaPlugin.name.replace(/\s/g, '-')),
fileName: 'manifest.json',
content: JSON.stringify(figmaPlugin),
}),
],
});