keyoxide-web/webpack.config.js

88 lines
2.7 KiB
JavaScript
Raw Permalink Normal View History

2022-02-27 14:59:17 -07:00
import { dirname, resolve } from 'path'
import { fileURLToPath } from 'url'
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
2022-03-15 15:26:40 -06:00
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import CopyPlugin from 'copy-webpack-plugin'
2022-02-25 11:18:46 -07:00
2022-02-27 14:59:17 -07:00
const __dirname = dirname(fileURLToPath(import.meta.url));
export default (env) => {
2022-02-25 11:18:46 -07:00
let config
if (env.static) {
config = {
mode: env.mode,
entry: {
main: {
2023-07-13 03:12:07 -06:00
import: './static-src/index.js'
}
2022-02-25 11:18:46 -07:00
},
output: {
filename: '[name].js',
2022-02-27 14:59:17 -07:00
path: resolve(__dirname, 'static'),
2022-03-15 15:26:40 -06:00
clean: true
2022-02-25 11:18:46 -07:00
},
watch: env.mode == "development",
module: {
rules: [
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader'
]
}
]
},
2022-02-27 14:59:17 -07:00
resolve: {
fallback: {
crypto: false,
2022-09-10 05:10:58 -06:00
assert: false,
util: false,
https: false,
http: false,
net: false,
url: false,
tls: false,
dns: false,
stream: false,
zlib: false,
querystring: false,
os: false,
child_process: false,
fs: false,
path: false,
2022-11-17 14:51:24 -07:00
buffer: false,
perf_hooks: false,
2022-02-27 14:59:17 -07:00
}
},
2022-02-25 11:18:46 -07:00
plugins: [
new MiniCssExtractPlugin(),
2022-03-15 15:26:40 -06:00
new CopyPlugin({
patterns: [
{ from: './static-src/files/', to: '../static/' },
2023-07-13 03:12:07 -06:00
{ from: './node_modules/openpgp/dist/openpgp.js', to: '../static/openpgp.js' },
{ from: './node_modules/doipjs/dist/doip.core.js', to: '../static/doip.js' },
{ from: './node_modules/doipjs/dist/doip.fetchers.minimal.js', to: '../static/doipFetchers.js' },
2022-03-15 15:26:40 -06:00
],
options: {
concurrency: 10,
},
}),
2022-02-25 11:18:46 -07:00
],
2023-07-13 03:12:07 -06:00
externals: {
doipjs: 'doip',
openpgp: 'openpgp'
}
2022-02-25 11:18:46 -07:00
}
} else {
return {}
}
if (env.mode == 'development') {
config.plugins.push(new BundleAnalyzerPlugin({
openAnalyzer: false
}))
}
return config
}