forked from compiler-explorer/compiler-explorer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
136 lines (127 loc) · 4.15 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
const path = require('path'),
webpack = require('webpack'),
CopyWebpackPlugin = require('copy-webpack-plugin'),
ExtractTextPlugin = require('extract-text-webpack-plugin'),
ManifestPlugin = require('webpack-manifest-plugin'),
glob = require("glob"),
UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const isDev = process.env.NODE_ENV === "DEV";
const outputPathRelative = 'dist/';
const staticRelative = 'static/';
const staticPath = path.resolve(__dirname, staticRelative);
const distPath = path.join(staticPath, outputPathRelative);
const vsPath = path.join(staticPath, 'vs/');
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 ? 'main.js' : 'bundle.[hash].js';
const cssName = isDev ? '[name].css' : "[name].[contenthash].css";
const publicPath = isDev ? '/dist/' : 'dist/';
const manifestPlugin = new ManifestPlugin({
fileName: manifestPath
});
const assetEntries = glob.sync(`${assetPath}/**/*.*`).reduce((obj, p) => {
const key = path.basename(p);
obj[key] = p;
return obj;
}, {});
let plugins = [
new CopyWebpackPlugin([{
from: 'node_modules/monaco-editor/min/vs',
to: vsPath,
},
{
from: path.join(staticPath, "favicon.ico"),
to: distPath,
},
]),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
}),
new ExtractTextPlugin(cssName),
manifestPlugin
];
if(!isDev) {
plugins.push(new UglifyJsPlugin({
sourceMap: true
}));
}
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
{
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
{
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/'),
vs: path.resolve(__dirname, 'node_modules/monaco-editor/min/vs')
}
},
stats: "errors-only",
devtool: 'source-map',
module: {
rules: [
{
test: /\.css$/,
exclude: path.resolve(__dirname, 'static/themes/'),
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: 'css-loader',
publicPath: './'
})
},
{
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
},
];