-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
80 lines (77 loc) · 2.26 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
var path = require('path');
const webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlInlineScriptPlugin = require('html-inline-script-webpack-plugin');
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
module.exports = (env, argv) => ({
mode: argv.mode === 'production' ? 'production' : 'development',
// This is necessary because Figma's 'eval' works differently than normal eval
devtool: argv.mode === 'production' ? false : 'inline-source-map',
entry: {
ui: '/src/ui/ui.tsx', // The entry point for your UI code
code: './src/plugin/code.ts', // The entry point for your plugin code
},
resolve: {
extensions: ['.ts', '.tsx', '.js'],
},
module: {
rules: [
// {
// test: /\.(js)$/,
// use: 'babel-loader',
// },
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
use: [
'style-loader',
{ loader: 'css-loader', options: { importLoaders: 1 } },
'postcss-loader',
],
},
// Allows you to use "<%= require('./file.svg') %>" in your HTML code to get a data URI
//{ test: /\.(png|jpg|gif|webp|zip)$/, use: [{ loader: 'url-loader' }] },
{
test: /\.(jpe?g|png|ttf|eot|woff(2)?)(\?[a-z0-9=&.]+)?$/,
use: 'base64-inline-loader'
},
{
test: /\.svg/,
type: 'asset/inline',
},
],
},
output: {
filename: (pathData) => {
return pathData.chunk.name === 'code'
? 'code.js'
: '[name].[contenthash].js';
},
path: path.resolve(__dirname, 'dist'), // Compile into a folder called "dist"
// Clean the output directory before emit.
clean: true,
publicPath: '',
},
plugins: [
new webpack.DefinePlugin({
global: {}, // Fix missing symbol error when running in developer VM
}),
new NodePolyfillPlugin({
includeAliases: ['browser', 'process', 'path']
}),
new HtmlWebpackPlugin({
inject: 'body',
template: './src/ui/ui.html',
filename: 'ui.html',
chunks: ['ui'],
}),
new HtmlInlineScriptPlugin({
htmlMatchPattern: [/ui.html/],
scriptMatchPattern: [/.js$/],
}),
],
});