BoostNote-App/webpack.config.ts

119 lines
2.6 KiB
TypeScript
Raw Permalink Normal View History

2019-09-18 05:25:34 +03:00
import path from 'path'
import webpack from 'webpack'
import HtmlWebpackPlugin from 'html-webpack-plugin'
2019-09-18 11:36:21 +03:00
import express from 'express'
import ErrorOverlayPlugin from 'error-overlay-webpack-plugin'
import CopyPlugin from 'copy-webpack-plugin'
2020-01-14 22:27:35 +03:00
import packageJson from './package.json'
2018-11-06 10:27:04 +03:00
2019-12-10 22:33:42 +03:00
module.exports = (env, argv) => {
2020-04-08 21:28:48 +03:00
const config: webpack.Configuration = {
entry: ['./src/index.tsx'],
2019-12-10 22:33:42 +03:00
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'electron', 'compiled'),
2019-12-10 22:33:42 +03:00
},
2018-11-06 10:27:04 +03:00
2019-12-10 22:33:42 +03:00
devtool: 'inline-source-map',
module: {
rules: [
{
test: /\.css$/i,
2020-04-08 07:14:38 +03:00
use: ['style-loader', 'css-loader'],
2019-12-10 22:33:42 +03:00
},
{
test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/i,
loader: 'url-loader',
options: {
2020-04-08 07:14:38 +03:00
limit: 8192,
},
2019-12-10 22:33:42 +03:00
},
{
test: /\.tsx?$/,
2020-02-14 10:35:10 +03:00
use: [{ loader: 'ts-loader', options: { transpileOnly: true } }],
2020-04-08 07:14:38 +03:00
exclude: /node_modules/,
2019-12-10 22:33:42 +03:00
},
{
test: /\.md$/,
use: [
{
2020-04-08 07:14:38 +03:00
loader: 'raw-loader',
},
],
},
],
2019-12-10 22:33:42 +03:00
},
2018-11-06 10:27:04 +03:00
2019-12-10 22:33:42 +03:00
plugins: [
new HtmlWebpackPlugin({
2020-04-08 07:14:38 +03:00
template: 'index.html',
2019-12-10 22:33:42 +03:00
}),
new ErrorOverlayPlugin(),
2020-01-14 22:27:35 +03:00
new webpack.DefinePlugin({
2020-04-08 07:14:38 +03:00
'process.env.VERSION': JSON.stringify(packageJson.version),
2020-01-14 22:27:35 +03:00
}),
2021-09-05 20:43:43 +03:00
new webpack.EnvironmentPlugin([
'NODE_ENV',
'BOOST_HUB_BASE_URL',
'MOCK_BACKEND',
]),
2020-10-21 04:59:15 +03:00
new CopyPlugin({
patterns: [
{
from: path.join(__dirname, 'static'),
to: 'app/static',
},
],
}),
2019-12-10 22:33:42 +03:00
],
2018-11-06 10:27:04 +03:00
2019-12-10 22:33:42 +03:00
devServer: {
host: 'localhost',
port: 3000,
2018-11-06 10:27:04 +03:00
2019-12-10 22:33:42 +03:00
historyApiFallback: {
2020-04-08 07:14:38 +03:00
index: '/app',
2019-12-10 22:33:42 +03:00
},
// respond to 404s with index.html
hot: true,
// enable HMR on the server
2020-04-08 07:14:38 +03:00
before: function (app, server) {
2019-12-19 03:09:56 +03:00
app.use('/app/static', express.static(path.join(__dirname, 'static')))
2020-04-08 07:14:38 +03:00
},
2019-10-11 11:42:29 +03:00
},
2019-09-18 11:36:21 +03:00
2019-12-10 22:33:42 +03:00
resolve: {
2020-04-08 07:14:38 +03:00
extensions: ['.tsx', '.ts', '.js'],
2019-12-10 22:33:42 +03:00
},
node: {
2020-04-08 07:14:38 +03:00
fs: 'empty',
},
2019-12-10 22:33:42 +03:00
}
if (argv.mode === 'development') {
config.plugins.unshift(new webpack.HotModuleReplacementPlugin())
2018-11-06 10:27:04 +03:00
2020-04-08 21:28:48 +03:00
config.entry = [
2019-12-10 22:33:42 +03:00
'react-hot-loader/patch',
'webpack-dev-server/client?http://localhost:3000',
2020-04-08 21:28:48 +03:00
'webpack/hot/only-dev-server',
...(config.entry as string[]),
]
config.output.publicPath = 'http://localhost:3000/app'
2019-12-17 14:21:31 +03:00
}
if (argv.mode === 'production') {
2020-04-08 21:28:48 +03:00
config.optimization = {
2019-12-17 14:21:31 +03:00
minimize: true,
}
config.output.path = path.resolve(__dirname, 'electron/compiled')
}
2019-12-10 22:33:42 +03:00
return config
2018-11-06 10:27:04 +03:00
}