forked from JetBrains/kotlin-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
126 lines (111 loc) · 2.92 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 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 = 'KotlinPlayground';
const webDemoUrl = params.webDemoUrl || 'https://api.kotlinlang.org/';
const examplesPath = isServer ? '' : 'examples/';
const pathDist = path.resolve(__dirname, 'dist');
const common = {
mode: env,
output: {
path: pathDist,
filename: '[name].js'
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.js$/,
include: path.resolve(__dirname, 'src'),
loader: 'babel-loader',
},
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.monk$/,
loader: 'monkberry-loader',
},
{
test: /\.s[ac]ss$/i,
use: ['style-loader', 'css-loader', 'sass-loader'],
},
{
test: /\.svg$/,
use: ['svg-url-loader', 'svg-fill-loader'],
type: 'javascript/auto',
},
{
test: /\.md$/,
loader: path.resolve(__dirname, 'utils/markdown-loader.js'),
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
plugins: [
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(env),
},
}),
],
};
const bundle = {
...common,
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: {
...common.output,
library: libraryName,
libraryTarget: 'umd',
libraryExport: 'default',
},
plugins: [
...common.plugins,
new HtmlPlugin({
template: 'examples.md',
filename: isServer ? 'index.html' : 'examples/index.html',
inject: false,
}),
new webpack.DefinePlugin({
__WEBDEMO_URL__: JSON.stringify(webDemoUrl),
__IS_PRODUCTION__: isProduction,
__LIBRARY_NAME__: JSON.stringify(libraryName),
}),
],
devServer: {
static: path.resolve(__dirname, 'src'),
},
}
const crosslink = {
...common,
target: 'node',
entry: {
crosslink: './src/lib/crosslink',
},
output: {
...common.output,
globalObject: 'this',
library: {
name: 'crosslink',
type: 'umd',
},
},
}
return [bundle, crosslink];
};