-
Notifications
You must be signed in to change notification settings - Fork 62
/
webpack.config.js
122 lines (116 loc) · 3.5 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
/*eslint-env node*/
const webpack = require('webpack'),
CleanWebpackPlugin = require('clean-webpack-plugin'),
FlowWebpackPlugin = require('flow-webpack-plugin'),
HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin'),
HtmlWebpackPlugin = require('html-webpack-plugin'),
UglifyJsPlugin = require('uglifyjs-webpack-plugin'),
WriteFilePlugin = require('write-file-webpack-plugin'),
env = require('./scripts/env'),
path = require('path');
const isDev = env.NODE_ENV === 'development' || 0;
const options = {
entry: {
convert: path.join(__dirname, 'demo', 'ConvertApp.js'),
demo: path.join(__dirname, 'demo', 'index.js'),
playground: path.join(__dirname, 'playground', 'playground.js'),
ui: path.join(__dirname, 'demo', 'UIExamples.js'),
},
output: {
path: path.join(__dirname, 'bin'),
filename: '[name].bundle.js',
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: [['env', {modules: false}], 'react', 'flow'],
plugins: [
'transform-export-extensions',
'transform-class-properties',
[
'transform-runtime',
{
helpers: true,
polyfill: true,
regenerator: true,
},
],
'flow-react-proptypes',
'transform-object-rest-spread',
'transform-flow-strip-types',
'syntax-dynamic-import',
],
},
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.html$/,
loader: 'html-loader',
exclude: /node_modules/,
},
{
test: /mathquill\.js$/,
include: [/node-mathquill/],
// Grab the MathQuill export
// NOTE: window.jQuery needs to be provided through the providePlugin
// unless https://github.com/webpack/imports-loader/pull/21 is merged
use: ['exports-loader?MathQuill'],
},
],
},
resolve: {
alias: {},
},
plugins: [
new webpack.ProvidePlugin({
// jQuery (for Mathquill)
'window.jQuery': 'jquery',
}),
new FlowWebpackPlugin(),
// clean the web folder
new CleanWebpackPlugin(['bin']),
// expose and write the allowed env vars on the compiled bundle
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(env.NODE_ENV),
}),
new HtmlWebpackPlugin({
template: path.join(__dirname, 'demo', 'index.html'),
filename: 'index.html',
chunks: ['demo'],
inlineSource: isDev ? '$^' : '.(js|css)$',
}),
new HtmlWebpackPlugin({
template: path.join(__dirname, 'demo', 'index.html'),
filename: 'playground.html',
chunks: ['playground'],
inlineSource: isDev ? '$^' : '.(js|css)$',
}),
new HtmlWebpackPlugin({
template: path.join(__dirname, 'demo', 'index.html'),
filename: 'ui.html',
chunks: ['ui'],
inlineSource: isDev ? '$^' : '.(js|css)$',
}),
new HtmlWebpackPlugin({
template: path.join(__dirname, 'demo', 'index.html'),
filename: 'convert.html',
chunks: ['convert'],
inlineSource: isDev ? '$^' : '.(js|css)$',
}),
new HtmlWebpackInlineSourcePlugin(),
new WriteFilePlugin(),
],
};
if (env.NODE_ENV === 'development') {
options.devtool = 'cheap-module-eval-source-map';
} else {
options.plugins.push(new UglifyJsPlugin());
}
module.exports = options;