factorio-server-manager/webpack.config.js

153 lines
5.5 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");
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
2018-08-29 05:08:55 +02:00
/**
* TODO remove when webpack fixed this error:
* Links to this error:
* https://github.com/webpack/webpack/issues/7300
* https://github.com/JeffreyWay/laravel-mix/pull/1495
* https://github.com/webpack-contrib/mini-css-extract-plugin/issues/151
* and more...
*
2018-08-29 05:08:55 +02:00
* As far as i know, this will be fixed in webpack 5
* ~knoxfighter
*/
const FixStyleOnlyEntriesPlugin = require("webpack-fix-style-only-entries");
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 ? "none" : "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: {
ident: 'postcss',
plugins: [
require('tailwindcss'),
require('autoprefixer'),
],
},
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 FixStyleOnlyEntriesPlugin(),
new MiniCssExtractPlugin({
filename: "[name].css"
2018-08-29 20:48:24 +02:00
}),
(isProduction) ?
new OptimizeCssAssetsPlugin({
cssProcessorPluginOptions: {
preset: ['default', { discardComments: { removeAll: true } }],
},
}) : () => {}
]
2018-08-29 18:11:46 +02:00
}
}