forked from gzuidhof/starboard-notebook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
126 lines (117 loc) · 3.64 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
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 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',
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.d.ts'],
alias: {
"react": path.resolve("./node_modules/preact/compat"),
"react-dom": path.resolve("./node_modules/preact/compat")
}
},
optimization: {
usedExports: true,
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: [
'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 MonacoWebpackPlugin({
languages: [
"markdown", "html", "css", "javascript", "typescript", "python", "coffee",
],
features: [
"!toggleHighContrast", "!gotoSymbol"
]
}),
],
devServer: {
contentBase: path.join(__dirname, './dist/'),
compress: true,
port: 9001,
hot: true,
historyApiFallback: false
},
}
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.stats = argv.stats
}
return config;
};