-
-
Notifications
You must be signed in to change notification settings - Fork 134
/
webpack.config.js
executable file
·130 lines (127 loc) · 3.04 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
const isDev = process.env.NODE_ENV !== 'production';
const isDevServer = process.env.WEBPACK_DEV_SERVER;
const path = require('path');
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const fs = require('fs');
let version = fs.readFileSync("IRIS_VERSION", "utf8");
version = version.replace(/\r?\n?/g, '').trim();
const build = Math.floor(Date.now() / 1000);
const config = {
mode: process.env.NODE_ENV,
context: path.resolve(__dirname),
entry: ['@babel/polyfill', './src/js/index'],
output: {
path: path.resolve(__dirname, 'mopidy_iris/static'),
filename: `app${isDev ? '' : '.min'}.js`,
},
module: {
rules: [
{
test: require.resolve('jquery'),
exclude: [
/node_modules/,
],
use: [
'expose-loader?jQuery!expose?$',
],
},
{
test: /.(jsx|js|ts|tsx)$/,
exclude: /node_modules/,
resolve: {
extensions: [".js", ".jsx", ".ts", ".tsx"]
},
use: [
{
loader: 'babel-loader',
},
],
},
{
test: /\.scss$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: './',
},
},
'css-loader',
'sass-loader',
],
},
{
test: /\.ya?ml$/,
type: 'json',
use: {
loader: 'yaml-loader',
options: { json: true, type: 'json' }
}
},
{
// load external resources (ie Google fonts)
test: /.(gif|png|woff(2)?|eot|ttf|svg)(\?[a-z0-9=\.]+)?$/,
type: 'asset/resource',
generator: {
filename: 'assets/[name][ext]',
},
},
(isDev ? {} : {
test: /\.(js|jsx)$/,
use: [
{
loader: 'webpack-strip',
options: {
strip: [
'console.log',
'console.info',
'debug',
],
},
},
],
}),
],
},
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery",
}),
new MiniCssExtractPlugin({
filename: `app${isDev ? '' : '.min'}.css`,
}),
new HtmlWebpackPlugin({
inject: false,
template: './src/index.html',
templateParameters: {
isDevServer: isDevServer ? 1 : 0,
baseHref: isDevServer ? '/' : '/iris/',
version: `${version}-${isDevServer ? 'DEV_SERVER' : ''}`,
build,
},
}),
],
watchOptions: {
poll: true,
},
devtool: (isDev ? 'source-map' : false),
devServer: {
historyApiFallback: true,
port: 6681,
client: {
overlay: true,
},
static: [
{
directory: path.join(__dirname, 'mopidy_iris', 'static', 'assets'),
publicPath: '/assets/',
},
],
},
};
// now export our collated config object
module.exports = config;