-
Notifications
You must be signed in to change notification settings - Fork 7
/
webpack.config.js
99 lines (96 loc) · 2.52 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
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const webpack = require('webpack');
const extractCss = new ExtractTextPlugin('index.css');
module.exports = {
entry: {
index: './src/index.js',
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
},
externals: {
mathjax: 'MathJax',
},
devtool: 'source-map',
module: {
rules: [
{
// upstream files that only need to be copied
include: [path.resolve(__dirname, 'node_modules')],
test: /\.(eot|ttf|woff2?)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: "file-loader",
query: {name: 'assets/[name].[md5:hash:hex:8].[ext]'},
},
{
// upstream images
include: [path.resolve(__dirname, 'node_modules')],
test: /\.(jpg|png|svg)$/,
use: [
{
loader: 'file-loader',
query: {name: 'assets/[name].[md5:hash:hex:8].[ext]'},
},
'image-webpack-loader',
],
},
{
// html templates
test: /\.html$/,
exclude: [path.resolve(__dirname, 'src/index.html')],
loader: 'html-loader',
query: {
interpolate: 'require', // allow ${require(...)} in html
},
},
{
// images that can be optimized
exclude: [path.resolve(__dirname, 'node_modules')],
test: /\.(jpg|png|svg)$/,
use: [
{
loader: 'file-loader',
query: {
context: 'src',
name: '[path][name].[md5:hash:hex:8].[ext]'
},
},
'image-webpack-loader',
],
},
{
// less to css
test: /\.less$/,
loader: extractCss.extract({
use: ['css-loader?sourceMap', 'less-loader?sourceMap'],
}),
},
{
// es6 to es5
test: /\.js$/,
exclude: /node_modules/,
use: [
{loader: 'ng-annotate-loader'},
{loader: 'babel-loader', query: {presets: ['es2015']}},
],
},
],
},
plugins: [
// TODO: require() this in translation config?
new CopyWebpackPlugin([
{from: {glob: 'nls/*.json'}, context: 'src', to: './'},
]),
extractCss,
new HtmlWebpackPlugin({
template: './src/index.html',
dev: process.env.NODE_ENV !== 'production'
}),
],
performance: {
hints: false,
},
};