factorio-server-manager/webpack.config.js

131 lines
4.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");
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';
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",
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",
"sass-loader?sourceMap"
]
},
{
test: /(\.(png|jpe?g|gif)$|^((?!font).)*\.svg$)/,
loaders: [
{
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$)/,
loaders: [
{
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 18:11:46 +02:00
}
}