forked from gzuidhof/starboard-notebook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
172 lines (162 loc) · 5.16 KB
/
webpack.config.js
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
const path = require("path");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const webpack = require('webpack')
const pkg = require("./package.json");
const baseConfig = {
entry: ['./src/publicPath.ts', './src/main.ts'],
output: {
path: path.resolve(__dirname, 'dist/'),
filename: "starboard-notebook.js",
chunkFilename: '[name].chunk.js',
crossOriginLoading: 'anonymous',
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.d.ts'],
alias: {
"react": path.resolve("./node_modules/preact/compat"),
"react-dom": path.resolve("./node_modules/preact/compat")
}
},
cache: {
type: "filesystem",
buildDependencies: {
config: [__filename],
},
},
optimization: {
moduleIds: "named",
chunkIds: "named",
usedExports: true,
splitChunks: false,
minimizer: [
new CssMinimizerPlugin(),
new TerserPlugin({
parallel: true,
terserOptions: {
compress: {
passes: 3,
},
ecma: 2018,
// https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
}
}),
]
},
stats: "minimal",
module: {
rules: [
{
test: /\.tsx?$/,
use: [
{
loader: "esbuild-loader",
options: {
loader: "ts",
target: "es2018",
},
}
],
exclude: [/node_modules/, /initServiceWorker\.ts$/],
},
{ // The ESBuild plugin is problematic for the service worker, so we use ts-loader for that..
test: /initServiceWorker\.tsx?$/,
use: [
{
loader: "ts-loader"
}
],
exclude: [/node_modules/],
},
{
test: /\.(s?css|sass)$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {}
},
'sass-loader'
]
},
{
test: /\.ttf$|\.woff2$/,
use: ['file-loader?name=[name].[ext]'],
exclude: [/.*KaTeX.*.ttf/],
},
{ // KaTeX ttf fonts are not omitted. Starboard only supports browsers that understand woff2 anyway.
test: /(KaTeX).*\.ttf$/,
use: ['file-loader?emitFile=false'],
},
{
test: /\.ico$|\.svg$|\.eot|\.woff$/,
use: ['file-loader?emitFile=false'],
},
]
},
plugins: [
new HtmlWebpackPlugin({
title: 'Starboard Notebook',
favicon: 'static/favicon.ico',
}),
new MiniCssExtractPlugin({
filename: "starboard-notebook.css"
}),
new webpack.DefinePlugin({
STARBOARD_NOTEBOOK_VERSION: JSON.stringify(pkg.version)
}),
new webpack.ProvidePlugin({
process: 'process/browser.js',
}),
new MonacoWebpackPlugin({
languages: [
"markdown", "html", "css", "javascript", "typescript", "python",
],
features: [
"!toggleHighContrast", "!gotoSymbol"
]
}),
],
devServer: {
// contentBase: path.join(__dirname, './dist/'),
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, OPTIONS",
},
compress: true,
port: 9001,
hot: true,
historyApiFallback: false,
headers: {
"Cross-Origin-Embedder-Policy": "require-corp",
"Cross-Origin-Opener-Policy": "same-origin",
"Access-Control-Allow-Origin": "*",
}
},
}
module.exports = (env, argv) => {
const config = baseConfig;
if (argv.mode === "development") {
config.devtool = 'inline-source-map'
config.output.publicPath = "/"
// We add it here so that in a production build it fails to import notebooks
config.module.rules.push({
test: /\.(nb|sbnb)$/,
use: 'raw-loader',
})
}
if (argv.stats) {
config.plugins.push(new BundleAnalyzerPlugin({
analyzerMode: "static"
}))
}
if (env.minify === "disabled") {
console.log("Building without minimization");
config.optimization.minimizer = [];
}
return config;
};