forked from compiler-explorer/compiler-explorer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
157 lines (149 loc) · 4.81 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
const path = require('path'),
webpack = require('webpack'),
CopyWebpackPlugin = require('copy-webpack-plugin'),
MiniCssExtractPlugin = require('mini-css-extract-plugin'),
ManifestPlugin = require('webpack-manifest-plugin'),
glob = require("glob"),
UglifyJsPlugin = require('uglifyjs-webpack-plugin'),
MonacoEditorWebpackPlugin = require('monaco-editor-webpack-plugin');
const isDev = process.env.NODE_ENV !== "production";
const outputPathRelative = 'dist/';
const staticRelative = 'static/';
const staticPath = path.resolve(__dirname, staticRelative);
const distPath = path.join(staticPath, outputPathRelative);
const assetPath = path.join(staticPath, "assets");
const manifestPath = 'manifest.json'; //if you change this, you also need to update it in the app.js
const outputName = isDev ? '[name].js' : '[name].[chunkhash].js';
const cssName = isDev ? '[name].css' : "[name].[contenthash].css";
const publicPath = isDev ? '/dist/' : 'dist/';
const manifestPlugin = new ManifestPlugin({
fileName: manifestPath,
publicPath: './'
});
const assetEntries = glob.sync(`${assetPath}/**/*.*`).reduce((obj, p) => {
const key = path.basename(p);
obj[key] = p;
return obj;
}, {});
let plugins = [
new MonacoEditorWebpackPlugin({
languages: ['cpp', 'go', 'rust', 'swift']
}),
new CopyWebpackPlugin([
{
from: path.join(staticPath, "favicon.ico"),
to: distPath
},
{
from: 'node_modules/es6-shim/es6-shim.min.js',
to: distPath
}
]),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
}),
new MiniCssExtractPlugin({
filename: cssName
}),
manifestPlugin
];
module.exports = [
//if you change the order of this, make sure to update the config variable in app.js
//server side stuff
// currently we just want to shove a cache path onto the static assets so we can get the hash onto the filename
//this means we can set the cache for eternity
{
mode: isDev ? 'development' : 'production',
entry: assetEntries,
output: {
path: path.join(distPath, 'assets'),
filename: '.[name].ignoreme'
},
module: {
rules: [
{
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[hash].[ext]'
}
}]
}
]
},
plugins: [
manifestPlugin
]
},
//this is the client side
{
mode: isDev ? 'development' : 'production',
entry: './static/main.js',
output: {
filename: outputName,
path: distPath,
publicPath: publicPath
},
resolve: {
modules: ['./static', "./node_modules"],
alias: {
//is this safe?
goldenlayout: path.resolve(__dirname, 'node_modules/golden-layout/'),
lzstring: path.resolve(__dirname, 'node_modules/lz-string/'),
filesaver: path.resolve(__dirname, 'node_modules/file-saver/')
}
},
stats: "normal",
devtool: 'source-map',
optimization: {
minimize: !isDev,
minimizer: [new UglifyJsPlugin({
parallel: true,
sourceMap: true,
uglifyOptions: {
output: {
comments: false,
beautify: false
}
}
})]
},
module: {
rules: [
{
test: /\.css$/,
exclude: path.resolve(__dirname, 'static/themes/'),
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: './',
hmr: isDev
}
},
'css-loader'
]
},
{
test: /\.css$/,
include: path.resolve(__dirname, 'static/themes/'),
use: ['css-loader']
},
{
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
loader: 'url-loader?limit=8192'
},
{
test: /\.(html)$/,
loader: 'html-loader',
options: {
minimize: !isDev
}
}
]
},
plugins: plugins
}
];