-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
134 lines (128 loc) · 2.96 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
const path = require('path')
const CopyPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const TerserPlugin = require('terser-webpack-plugin')
const ZipPlugin = require('zip-webpack-plugin')
const IS_DEV = process.env.NODE_ENV !== 'production'
const IS_UXP = process.env.TYPE === 'uxp'
console.log(IS_DEV ? 'DEVELOPMENT BUILD' : 'PRODUCTION BUILD')
console.log(`BUILDING ${IS_UXP ? 'UXP PLUGIN' : 'CEP EXTENSION'}`)
const config = {
entry: `./src/index_${IS_UXP ? 'uxp' : 'cep'}.ts`,
mode: IS_DEV ? 'development' : 'production',
target: 'node',
devtool: false,
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: (loader) => [
require('postcss-import')({
root: loader.resourcePath,
}),
require('postcss-preset-env')({
browsers: 'last 2 versions',
}),
...(IS_DEV ? [] : [require('cssnano')()]),
],
},
},
},
],
},
],
},
resolve: {
extensions: ['.ts', '.js'],
},
externals: {
photoshop: 'commonjs2 photoshop',
uxp: 'commonjs2 uxp',
os: 'commonjs2 os',
},
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist'),
},
plugins: [
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: '[name].bundle.css',
}),
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'src/index.ejs',
scriptLoading: 'defer',
minify: false,
inject: false,
// Custom variable to be used in template
isCEP: !IS_UXP,
isUXP: IS_UXP,
}),
new CopyPlugin({
patterns: [
{
from: './plugin',
globOptions: {
ignore: IS_DEV ? [] : ['**/.debug'],
},
},
],
}),
],
watchOptions: {
ignored: ['dist', 'node_modules'],
},
}
//* Additional steps for production build
if (!IS_DEV) {
config.optimization = {
moduleIds: 'named',
minimize: true,
minimizer: [
// Make code smaller but keep it somehow readable since it is open-source.
// So it will be easier to debug production builds.
new TerserPlugin({
extractComments: true,
parallel: true,
terserOptions: {
mangle: false,
compress: {
conditionals: false,
drop_console: true,
drop_debugger: true,
comparisons: false,
collapse_vars: false,
booleans: false,
inline: false,
keep_classnames: true,
},
},
}),
],
}
//* Pack plugin automatically in ./release folder
config.plugins.push(
new ZipPlugin({
path: '../release',
pathPrefix: 'wakatime-adobe',
filename: `wakatime-adobe-${IS_UXP ? 'uxp' : 'cep'}`,
extension: 'zip',
})
)
}
module.exports = config