-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
91 lines (78 loc) · 2.07 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
const path = require('path')
// Plugins
const HtmlWebpackPlugin = require('html-webpack-plugin'),
HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin'),
WebpackMessages = require('webpack-messages'),
MiniCssExtractPlugin = require('mini-css-extract-plugin'),
CopyPlugin = require('copy-webpack-plugin') // added by me
console.clear()
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',
stats: false,
entry: {
main: './src/main.ts',
ui: './src/ui.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',
]
},
]
},
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({ patterns: [{
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)
}
}
}]})
],
})