forked from fsharp/TryFSharp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
178 lines (173 loc) · 5.56 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
173
174
175
176
177
178
// Template for webpack.config.js in Fable projects
// Find latest version in https://github.com/fable-compiler/webpack-config-template
var CONFIG = {
indexHtmlTemplate: "./src/index.html",
fsharpEntry: "./src/App/App.fsproj",
cssEntry: "./src/style/main.scss",
outputDir: "./docs",
assetsDir: "./public",
// It's important to use this port, check src/App/Shared.fs
devServerPort: 8080,
babel: {
presets: [
"@babel/preset-react",
["@babel/preset-env", {
"targets": {
"browsers": ["last 2 versions"]
},
"modules": false
}]
],
plugins: [
"@babel/plugin-proposal-class-properties"
]
}
}
// If we're running the webpack-dev-server, assume we're in development mode
var isProduction = !process.argv.find(v => v.indexOf('webpack-dev-server') !== -1);
console.log("Bundling for " + (isProduction ? "production" : "development") + "...");
var path = require("path");
var webpack = require("webpack");
var HtmlWebpackPlugin = require('html-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var MiniCssExtractPlugin = require("mini-css-extract-plugin");
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
const WorkboxPlugin = require('workbox-webpack-plugin');
// The HtmlWebpackPlugin allows us to use a template for the index.html page
// and automatically injects <script> or <link> tags for generated bundles.
var commonPlugins = [
new HtmlWebpackPlugin({
filename: 'index.html',
template: CONFIG.indexHtmlTemplate
}),
new MonacoWebpackPlugin({
languages: [
"fsharp",
"html",
"css",
"javascript",
// We need typescript too, see https://github.com/Microsoft/monaco-editor-webpack-plugin/issues/27
"typescript"
],
features: [
'accessibilityHelp',
'bracketMatching',
'caretOperations',
'clipboard',
'codelens',
'colorDetector',
'comment',
'contextmenu',
// 'coreCommands',
'cursorUndo',
// 'dnd',
'find',
// 'folding',
// 'format',
'goToDefinitionCommands',
'goToDefinitionMouse',
'gotoError',
'gotoLine',
'hover',
'inPlaceReplace',
'inspectTokens',
// 'iPadShowKeyboard',
'linesOperations',
'links',
'multicursor',
'parameterHints',
// 'quickCommand',
// 'quickFixCommands',
// 'quickOutline',
// 'referenceSearch',
// 'rename',
'smartSelect',
// 'snippets',
'suggest',
'toggleHighContrast',
'toggleTabFocusMode',
'transpose',
'wordHighlighter',
'wordOperations'
]
})
];
module.exports = {
entry: isProduction ? {
app: [CONFIG.fsharpEntry, CONFIG.cssEntry]
} : {
app: [CONFIG.fsharpEntry],
style: [CONFIG.cssEntry]
},
output: {
path: path.join(__dirname, CONFIG.outputDir),
filename: isProduction ? '[name].[hash].js' : '[name].js',
// Fix for HMR + worker: https://github.com/webpack/webpack/issues/6642#issuecomment-370222543
globalObject: 'self',
},
mode: isProduction ? "production" : "development",
// devtool: isProduction ? "source-map" : "eval-source-map",
plugins: isProduction ?
commonPlugins.concat([
new MiniCssExtractPlugin({ filename: 'style.css' }),
new CopyWebpackPlugin([{ from: CONFIG.assetsDir }]),
new WorkboxPlugin.GenerateSW({
// these options encourage the ServiceWorkers to get in there fast
// and not allow any straggling "old" SWs to hang around
clientsClaim: true,
skipWaiting: true,
// runtimeCaching: [{
// urlPattern: new RegExp('/api/.*'),
// handler: 'staleWhileRevalidate'
// }]
}),
])
: commonPlugins.concat([
new webpack.HotModuleReplacementPlugin(),
]),
devServer: {
publicPath: "/",
contentBase: CONFIG.assetsDir,
port: CONFIG.devServerPort,
proxy: CONFIG.devServerProxy,
hot: true,
inline: true
},
module: {
rules: [
{
test: /\.worker\.js$/,
use: "worker-loader"
},
{
test: /\.fs(x|proj)?$/,
use: {
loader: "fable-loader",
options: {
babel: CONFIG.babel
}
}
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: CONFIG.babel
},
},
{
test: /\.(sass|scss|css)$/,
use: [
isProduction ? MiniCssExtractPlugin.loader : 'style-loader',
'css-loader',
'sass-loader',
],
},
{
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)(\?.*$|$)/,
use: ["file-loader"]
}
]
}
};