-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
96 lines (86 loc) · 2.4 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
const path = require('path')
// Plugins
const HtmlWebpackPlugin = require('html-webpack-plugin'),
HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin'),
MiniCssExtractPlugin = require('mini-css-extract-plugin'),
WebpackMessages = require('webpack-messages'),
CopyPlugin = require('copy-webpack-plugin');
console.clear()
module.exports = (env, argv) => {
return {
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',
stats: false,
entry: {
main: './src/main.entry.ts',
ui: './src/ui.entry.js',
},
output: {
filename: '[name].js',
path: path.join(__dirname, 'build'),
},
module: {
rules: [
// JS and TS
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: [
'babel-loader',
]
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
'babel-loader',
'ts-loader'
]
},
// CSS and SCSS
{
test: /\.s?css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader',
]
},
{
test: /\.(jpe?g|png|ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/,
use: 'base64-inline-loader?limit=100000&name=[name].[ext]'
}
],
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx', '.scss', '.html',],
},
plugins: [
new MiniCssExtractPlugin({filename: '[name].css'}),
new HtmlWebpackPlugin({
filename: 'ui.html',
template: './src/ui.html',
inlineSource: '.(js|css)$',
chunks: ['ui'],
}),
new HtmlWebpackInlineSourcePlugin(),
new WebpackMessages(),
// added by me
new CopyPlugin([
{
from: './src/manifest.json',
to: './manifest.json',
transform: (content, path) => {
try {
const str = content.toString().replace('__STATE__', (argv.mode === 'production' ? '🚀 PROD' : '⚙️ DEV'))
return Buffer.from(str)
} catch (error) {
console.error(error)
}
}
},
])
],
}
}