-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
74 lines (72 loc) · 2.69 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
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlInlineScriptPlugin = require('html-inline-script-webpack-plugin');
const HtmlInlineCSSWebpackPlugin = require('html-inline-css-webpack-plugin').default;
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin');
const { CleanWebpackPlugin } = require('clean-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.js',
'./src/ui/js/reactivity.js',
'./src/ui/js/export-multi.js',
'./src/ui/js/export-single.js',
'./src/ui/js/backend-communication.js'
],
app: ['./src/app.ts'] // This is the entry point for our plugin code.
},
module: {
rules: [
// Converts TypeScript code to JavaScript
{ test: /\.tsx?$/, use: 'ts-loader', exclude: /node_modules/ },
// Enables including CSS by doing "import './file.css'" in your TypeScript code
// { test: /\.css$/i, use: [MiniCssExtractPlugin.loader, 'css-loader'] },
{ test: /\.(s[ac]ss|css)$/i, use: ['style-loader', 'css-loader', 'sass-loader'] },
// Allows you to use "<%= require('./file.svg') %>" in your HTML code to get a data URI
{ test: /\.(png|jpg|gif|webp|svg)$/, use: ['url-loader'] },
// {
// test: /\.(woff|woff2|eot|ttf|otf)$/i,
// type: 'src/ui/assets/fonts',
// generator: {
// filename: 'fonts/[name][ext][query]', // Organize fonts into a directory
// }
// }
],
},
// Webpack tries these extensions for you if you omit the extension like "import './file'"
resolve: {
extensions: ['.ts', '.js'],
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
},
// Tells Webpack to generate "ui.html" and to inline "ui.ts" into it
plugins: [
new webpack.DefinePlugin({
global: {}, // Fix missing symbol error when running in developer VM
}),
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
inject: 'body',
template: './src/ui.html',
filename: 'ui.html',
inlineSource: '.(js|css)$',
chunks: ['ui'],
minify: true,
cache: false
}),
new HtmlInlineScriptPlugin({
htmlMatchPattern: [/ui.html/],
scriptMatchPattern: [/.js$/]
}),
new HtmlInlineCSSWebpackPlugin(),
// new MiniCssExtractPlugin()
// new HtmlWebpackInlineSourcePlugin()
]
});