BoostNote-App/webpack.config.ts

143 lines
3.3 KiB
TypeScript
Raw 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'
2019-12-17 12:38:25 +03:00
import TerserPlugin from 'terser-webpack-plugin'
2018-11-06 10:27:04 +03:00
2019-12-10 22:33:42 +03:00
module.exports = (env, argv) => {
const config = {
entry: [
'./src/index.tsx'
// the entry point of our app
],
output: {
filename: 'bundle.js',
// the output bundle
2019-12-17 12:38:25 +03:00
path: path.resolve(__dirname, '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',
2019-12-17 12:38:25 +03:00
2019-12-10 22:33:42 +03:00
module: {
rules: [
{
test: /\.css$/i,
use: ['style-loader', 'css-loader']
},
{
test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/i,
loader: 'url-loader',
options: {
limit: 8192
2019-12-09 06:22:32 +03:00
}
2019-12-10 22:33:42 +03:00
},
{
test: /\.tsx?$/,
use: [{ loader: 'ts-loader' }],
exclude: /node_modules/
},
{
test: /\.md$/,
use: [
{
loader: 'raw-loader'
}
]
}
]
},
2018-11-06 10:27:04 +03:00
2019-12-10 22:33:42 +03:00
plugins: [
new webpack.NamedModulesPlugin(),
// prints more readable module names in the browser console on HMR updates
new webpack.NoEmitOnErrorsPlugin(),
// do not emit compiled assets that include errors
new HtmlWebpackPlugin({
template: 'index.html'
}),
new ErrorOverlayPlugin(),
new webpack.EnvironmentPlugin([
'NODE_ENV',
'AMPLIFY_AUTH_IDENTITY_POOL_ID',
'AMPLIFY_AUTH_REGION',
'AMPLIFY_PINPOINT_APPID',
'AMPLIFY_PINPOINT_REGION',
'BOOST_NOTE_BASE_URL'
]),
new CopyPlugin([
{
from: path.join(__dirname, 'node_modules/codemirror/theme'),
2019-12-10 23:31:03 +03:00
to: 'app/codemirror/theme'
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: {
index: '/app'
},
// respond to 404s with index.html
hot: true,
// enable HMR on the server
2019-12-17 14:21:31 +03:00
before: function (app, server) {
2019-12-10 22:33:42 +03:00
app.use(
2019-12-10 23:31:03 +03:00
'/app/codemirror/mode',
2019-12-10 22:33:42 +03:00
express.static(path.join(__dirname, 'node_modules/codemirror/mode'))
)
app.use(
2019-12-10 23:31:03 +03:00
'/app/codemirror/addon',
2019-12-10 22:33:42 +03:00
express.static(path.join(__dirname, 'node_modules/codemirror/addon'))
)
app.use(
2019-12-10 23:31:03 +03:00
'/app/codemirror/theme',
2019-12-10 22:33:42 +03:00
express.static(path.join(__dirname, 'node_modules/codemirror/theme'))
)
}
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: {
extensions: ['.tsx', '.ts', '.js']
},
node: {
fs: 'empty'
2019-09-18 11:36:21 +03:00
}
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
2019-12-10 22:33:42 +03:00
config.entry.unshift(
'react-hot-loader/patch',
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server'
)
2019-12-17 14:21:31 +03:00
; (config.output as any).publicPath = '/app'
}
if (argv.mode === 'production') {
(config as any).optimization = {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
keep_fnames: /Block|Value|Bool|BooleanLiteral|Null|NullLiteral|Literal|NumberLiteral|StringLiteral|RegexLiteral|Arr|Obj|Op|Parens/
}
})
]
}
2018-11-06 10:27:04 +03:00
}
2019-12-10 22:33:42 +03:00
return config
2018-11-06 10:27:04 +03:00
}