forked from BoostIO/BoostNote.next-local
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
172 lines (157 loc) · 4.47 KB
/
webpack.config.ts
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import path from 'path'
import webpack from 'webpack'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import express from 'express'
import ErrorOverlayPlugin from 'error-overlay-webpack-plugin'
import CopyPlugin from 'copy-webpack-plugin'
import packageJson from './package.json'
module.exports = (env, argv) => {
const config: webpack.Configuration = {
entry: ['./src/index.tsx'],
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'compiled'),
},
devtool: 'inline-source-map',
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,
},
},
{
test: /\.tsx?$/,
use: [{ loader: 'ts-loader', options: { transpileOnly: true } }],
exclude: /node_modules/,
},
{
test: /\.md$/,
use: [
{
loader: 'raw-loader',
},
],
},
],
},
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.DefinePlugin({
'process.env.VERSION': JSON.stringify(packageJson.version),
}),
new webpack.EnvironmentPlugin(['NODE_ENV']),
new CopyPlugin({
patterns: [
{
from: path.join(__dirname, 'node_modules/codemirror/lib/codemirror.css'),
to: 'app/codemirror/theme/codemirror.css',
},
{
from: path.join(__dirname, 'node_modules/codemirror/theme'),
to: 'app/codemirror/theme',
},
{
from: path.join(__dirname, 'static'),
to: 'app/static',
},
{
from: path.join(__dirname, 'node_modules/katex/dist/katex.min.css'),
to: 'app/katex/katex.min.css',
},
{
from: path.join(__dirname, 'node_modules/katex/dist/fonts/'),
to: 'app/katex/fonts/',
},
{
from: path.join(
__dirname,
'node_modules/remark-admonitions/styles/classic.css'
),
to: 'app/remark-admonitions/classic.css',
},
],
}),
],
devServer: {
host: 'localhost',
port: 3000,
historyApiFallback: {
index: '/app',
},
// respond to 404s with index.html
hot: true,
// enable HMR on the server
before: function (app, server) {
app.use(
'/app/codemirror/mode',
express.static(path.join(__dirname, 'node_modules/codemirror/mode'))
)
app.use(
'/app/codemirror/addon',
express.static(path.join(__dirname, 'node_modules/codemirror/addon'))
)
app.use(
'/app/codemirror/theme',
express.static(path.join(__dirname, 'node_modules/codemirror/theme'))
)
app.use(
'/app/katex/katex.min.css',
express.static(
path.join(__dirname, 'node_modules/katex/dist/katex.min.css')
)
)
app.use(
'/app/remark-admonitions/classic.css',
express.static(
path.join(
__dirname,
'node_modules/remark-admonitions/styles/classic.css'
)
)
)
app.use('/app/static', express.static(path.join(__dirname, 'static')))
},
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
node: {
fs: 'empty',
},
}
if (argv.mode === 'development') {
config.plugins.unshift(new webpack.HotModuleReplacementPlugin())
config.entry = [
'react-hot-loader/patch',
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
...(config.entry as string[]),
]
config.output.publicPath = 'http://localhost:3000/app'
}
if (argv.mode === 'production') {
config.optimization = {
minimize: true,
}
if (process.env.TARGET === 'electron') {
config.output.path = path.resolve(__dirname, 'electron/compiled')
} else {
config.output.publicPath = '/app/'
}
}
return config
}