factorio-server-manager/webpack.config.js

142 lines
5.0 KiB
JavaScript
Raw Normal View History

const path = require('path');
2018-08-20 19:38:33 +02:00
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
2023-10-29 20:24:16 +02:00
const TerserPlugin = require('terser-webpack-plugin');
2018-08-29 18:11:46 +02:00
module.exports = (env, argv) => {
const isProduction = argv.mode === 'production';
2018-08-29 18:11:46 +02:00
return {
entry: {
bundle: './ui/index.js',
style: './ui/index.scss'
},
2018-08-29 18:11:46 +02:00
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'app'),
publicPath: ""
},
resolve: {
alias: {
Utilities: path.resolve('ui/js/')
2018-08-20 19:38:33 +02:00
},
2018-08-29 18:11:46 +02:00
extensions: ['.js', '.json', '.jsx']
},
devtool: isProduction ? false : "source-map",
2018-08-29 18:11:46 +02:00
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: {
2018-08-29 19:17:11 +02:00
loader: 'babel-loader',
options: {
presets: [
'@babel/preset-env',
[
'@babel/preset-react', {
development: !isProduction
}
]
]
}
2018-08-29 18:11:46 +02:00
}
},
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
"sourceMap": !isProduction,
}
},
"resolve-url-loader",
2019-10-10 02:52:43 +02:00
{
loader: "sass-loader",
options: {
// always make sourceMap. resolver-url-loader is needing it
"sourceMap": true,
}
2020-08-22 20:34:09 +02:00
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
require('tailwindcss'),
require('autoprefixer'),
],
}
2020-08-22 20:34:09 +02:00
},
2019-10-10 02:52:43 +02:00
}
2018-08-29 18:11:46 +02:00
]
},
{
test: /(\.(png|jpe?g|gif)$|^((?!font).)*\.svg$)/,
use: [
2018-08-29 18:11:46 +02:00
{
loader: "file-loader",
options: {
name: loader_path => {
if (!/node_modules/.test(loader_path)) {
return "/images/[name].[ext]?[hash]";
}
2018-08-20 19:38:33 +02:00
2018-08-29 18:11:46 +02:00
return (
"/images/vendor/" +
loader_path.replace(/\\/g, "/")
.replace(/((.*(node_modules))|images|image|img|assets)\//g, '') +
'?[hash]'
);
},
}
2018-08-20 19:38:33 +02:00
}
2018-08-29 18:11:46 +02:00
]
},
{
test: /(\.(woff2?|ttf|eot|otf)$|font.*\.svg$)/,
use: [
2018-08-29 18:11:46 +02:00
{
loader: "file-loader",
options: {
name: loader_path => {
if (!/node_modules/.test(loader_path)) {
return '/fonts/[name].[ext]?[hash]';
}
2018-08-20 19:38:33 +02:00
2018-08-29 18:11:46 +02:00
return (
'/fonts/vendor/' +
loader_path
.replace(/\\/g, '/')
.replace(/((.*(node_modules))|fonts|font|assets)\//g, '') +
'?[hash]'
);
},
}
2018-08-20 19:38:33 +02:00
}
2018-08-29 18:11:46 +02:00
]
}
]
},
performance: {
hints: false
},
stats: {
children: false
},
plugins: [new MiniCssExtractPlugin()],
optimization: {
2023-10-29 20:24:16 +02:00
minimize: isProduction,
minimizer: [
new MiniCssExtractPlugin(
{
filename: "[name].css"
}
),
2023-10-29 20:24:16 +02:00
new TerserPlugin()
],
}
2018-08-29 18:11:46 +02:00
}
}