Files
Iris/webpack.config.js

131 lines
3.0 KiB
JavaScript
Raw Permalink Normal View History

const isDev = process.env.NODE_ENV !== 'production';
const isDevServer = process.env.WEBPACK_DEV_SERVER;
2017-03-08 09:13:24 +13:00
const path = require('path');
const webpack = require('webpack');
2019-04-12 09:59:37 +12:00
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
2022-10-29 21:55:00 +13:00
const HtmlWebpackPlugin = require('html-webpack-plugin');
2016-10-03 14:44:27 +13:00
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);
2017-03-08 09:13:24 +13:00
const config = {
2021-11-21 19:57:15 +13:00
mode: process.env.NODE_ENV,
context: path.resolve(__dirname),
entry: ['@babel/polyfill', './src/js/index'],
output: {
path: path.resolve(__dirname, 'mopidy_iris/static'),
2022-09-04 20:50:20 +12:00
filename: `app${isDev ? '' : '.min'}.js`,
2021-11-21 19:57:15 +13:00
},
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',
2022-09-04 09:03:11 +12:00
use: {
loader: 'yaml-loader',
options: { json: true, type: 'json' }
}
2021-11-21 19:57:15 +13:00
},
{
// load external resources (ie Google fonts)
test: /.(gif|png|woff(2)?|eot|ttf|svg)(\?[a-z0-9=\.]+)?$/,
2022-09-04 09:03:11 +12:00
type: 'asset/resource',
generator: {
filename: 'assets/[name][ext]',
},
2021-11-21 19:57:15 +13:00
},
(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({
2022-09-04 20:50:20 +12:00
filename: `app${isDev ? '' : '.min'}.css`,
2021-11-21 19:57:15 +13:00
}),
new HtmlWebpackPlugin({
inject: false,
template: './src/index.html',
templateParameters: {
isDevServer: isDevServer ? 1 : 0,
baseHref: isDevServer ? '/' : '/iris/',
version: `${version}-${isDevServer ? 'DEV_SERVER' : ''}`,
build,
},
}),
2021-11-21 19:57:15 +13:00
],
watchOptions: {
poll: true,
},
devtool: (isDev ? 'source-map' : false),
2022-10-29 21:55:00 +13:00
devServer: {
historyApiFallback: true,
port: 6681,
client: {
overlay: true,
},
static: [
{
directory: path.join(__dirname, 'mopidy_iris', 'static', 'assets'),
publicPath: '/assets/',
},
],
2022-10-29 21:55:00 +13:00
},
2016-10-03 14:44:27 +13:00
};
// now export our collated config object
module.exports = config;