Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
155 lines (150 loc) · 3.51 KB
/
Copy pathwebpack.config.js
File metadata and controls
155 lines (150 loc) · 3.51 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
const path = require('path');
const webpack = require('webpack'); // ← 1) new import
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const ZoteroLocalePlugin = require('./webpack.zotero-locale-plugin');
const babelConfigs = new Map([
['zotero', {
presets: [
['@babel/preset-env', { useBuiltIns: false }],
],
}],
['web', {
presets: [
["@babel/preset-env", {
targets: 'firefox >= 68, chrome >= 67, edge >= 79, safari >= 11, last 2 versions, not dead, not ie 11, not ie 10',
corejs: { version: 3.37 },
useBuiltIns: "usage",
}]
]
}],
]);
function generateEditorConfig(build) {
let config = {
name: build,
mode: build === 'dev' ? 'development' : 'production',
devtool: build === 'dev' ? 'source-map' : (build === 'zotero' ? false : 'source-map'),
entry: {
editor: [
`./src/index.${build}.js`,
'./src/stylesheets/main.scss'
]
},
output: {
path: path.resolve(__dirname, `./build/${build}`),
filename: '[name].js',
publicPath: '',
library: {
name: 'zotero-editor',
type: 'umd',
umdNamedDefine: true,
},
},
optimization: {
minimize: build !== 'dev',
minimizer: build === 'dev' ? [] : [new TerserPlugin({ extractComments: false }), new CssMinimizerPlugin()],
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: {
and: [/node_modules/],
not: build === 'web'
// some dependencies need to be transpiled for web, see zotero/web-library#556
? [
/@benrbray[\\/]prosemirror-math/,
]
: []
},
use: {
loader: 'babel-loader',
options: babelConfigs.get(build) ?? {},
},
},
{
test: /\.s?css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
},
{
loader: 'postcss-loader',
},
{
loader: 'sass-loader',
options: {
additionalData: `$platform: '${build}';`
}
},
],
},
{
test: /\.svg$/i,
issuer: /\.[jt]sx?$/,
use: ['@svgr/webpack'],
},
{
test: /\.woff2$/,
type: 'asset/resource',
generator: {
filename: 'assets/fonts/[name].[hash:8][ext]',
},
},
{
test: /\.(ttf|woff)$/,
type: 'asset/resource',
generator: {
emit: false,
},
},
{
test: /\.ftl$/,
type: 'asset/source'
}
]
},
plugins: [
new ZoteroLocalePlugin({
files: ['zotero.ftl', 'note-editor.ftl'],
locales: ['en-US'],
commitHash: 'b4f1deb998cca0eae6234dafcb9c3b41405a943e',
}),
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: '[name].css',
}),
new HtmlWebpackPlugin({
template: `./html/editor.${build}.html`,
filename: './[name].html',
}),
new webpack.DefinePlugin({ __BUILD__: JSON.stringify(build) })
],
};
if (build === 'zotero') {
config.externals = {
react: 'React',
'react-dom': 'ReactDOM',
'prop-types': 'PropTypes',
};
}
else if (build === 'dev') {
config.devServer = {
static: {
directory: path.resolve(__dirname, 'build/'),
watch: true,
},
devMiddleware: {
writeToDisk: true,
},
open: `/dev/editor.html`,
port: 3002,
};
}
return config;
}
module.exports = ['dev', 'web', 'zotero', 'ios', 'android'].map(generateEditorConfig);