forked from JetBrains/kotlin-playground
-
Notifications
You must be signed in to change notification settings - Fork 5
/
webpack.config.js
105 lines (91 loc) · 2.66 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
const path = require("path");
const webpack = require("webpack");
const HtmlPlugin = require("html-webpack-plugin");
module.exports = (params = {}) => {
const isProduction = params.production;
const env = isProduction ? "production" : "development";
const mainEntryName = isProduction ? "playground.min" : "playground";
const isServer = process.argv[1].includes("webpack-dev-server");
const libraryName = "QuicktypePlayground";
const examplesPath = isServer ? "" : "examples/";
const config = {
entry: {
[mainEntryName]: "./src/index",
REMOVE_ME: [
`!!file-loader?name=${examplesPath}examples.css!github-markdown-css/github-markdown.css`,
`!!file-loader?name=${examplesPath}examples-highlight.css!highlight.js/styles/github.css`
]
},
output: {
path: path.resolve(__dirname, "dist"),
filename: "[name].js",
library: libraryName,
libraryTarget: "umd",
libraryExport: "default"
},
devtool: "source-map",
module: {
rules: [
{
test: /\.js$/,
include: path.resolve(__dirname, "src"),
loader: "babel-loader"
},
{
test: /\.monk$/,
loader: "monkberry-loader"
},
{
test: /\.scss$/,
use: ["style-loader", "css-loader", "sass-loader"]
},
{
test: /\.svg$/,
use: ["svg-url-loader", "svg-fill-loader"]
},
{
test: /\.md$/,
loader: path.resolve(__dirname, "utils/markdown-loader.js")
}
]
},
plugins: [
new HtmlPlugin({
template: "examples.md",
filename: isServer ? "index.html" : "examples/index.html",
inject: false
}),
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.DefinePlugin({
__IS_PRODUCTION__: isProduction,
__LIBRARY_NAME__: JSON.stringify(libraryName),
"process.env": {
NODE_ENV: JSON.stringify(env)
}
}),
// Remove all removeme* assets
{
apply: compiler => {
compiler.plugin("emit", (compilation, done) => {
const { assets } = compilation;
Object.keys(assets).forEach(name => {
if (name.includes("REMOVE_ME")) {
delete assets[name];
}
});
done();
});
}
}
],
// Some libraries import Node modules but don't use them in the browser.
// Tell Webpack to provide empty mocks for them so importing them works.
node: {
fs: "empty"
},
devServer: {
contentBase: path.resolve(__dirname, "src")
}
};
return config;
};