// Copyright 2020 Thomas Hintz // // This file is part of the Alpha Centauri Farming project. // // The Alpha Centauri Farming project is free software: you can // redistribute it and/or modify it under the terms of the GNU General // Public License as published by the Free Software Foundation, either // version 3 of the License, or (at your option) any later version. // // The Alpha Centauri Farming project is distributed in the hope that // it will be useful, but WITHOUT ANY WARRANTY; without even the // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with the Alpha Centauri Farming project. If not, see // . const path = require('path'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const { CleanWebpackPlugin } = require('clean-webpack-plugin'); const FaviconsWebpackPlugin = require('favicons-webpack-plugin') const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const CopyPlugin = require('copy-webpack-plugin'); const webpack = require("webpack"); const autoprefixer = require("autoprefixer"); const CssUrlRelativePlugin = require('css-url-relative-plugin') module.exports = { entry: { app: './src/index.jsx', }, output: { filename: './assets/[name].[hash].js', path: path.resolve(__dirname, 'dist'), }, optimization: { runtimeChunk: 'single', splitChunks: { cacheGroups: { vendor: { test: /[\\/]node_modules[\\/]/, name: 'vendors', chunks: 'all', }, }, }, }, plugins: [ new CleanWebpackPlugin(), new HtmlWebpackPlugin({ title: 'Alpha Centauri Farming', filename: 'index.html', meta: {viewport: 'width=device-width, initial-scale=1'}, }), new FaviconsWebpackPlugin('./assets/img/tractor.svg'), new MiniCssExtractPlugin({ filename: './assets/[name].[hash].css', chunkFilename: './assets/[id].[hash].css', }), new CopyPlugin([ { from: './src/server/farm.scm', to: './[name].[ext]' }, { from: './src/server/farm', to: './[name]' }, { from: './assets/game/', to: './assets/game/' } ]), new webpack.LoaderOptionsPlugin({ options: { postcss: [ autoprefixer() ] } }), new CssUrlRelativePlugin() ], module: { rules: [ { test: /\.m?(js|jsx)$/, exclude: /(node_modules|bower_components)/, use: { loader: 'babel-loader', options: { presets: [['@babel/preset-env', { modules: false }], "@babel/preset-react",], } } }, // { // test: /mars-texture.png$/, // loader: 'file-loader', // options: { // name: './assets/img/[name].[contenthash].[ext]', // }, // }, { test: /\.(svg|png|gif)$/, loader: 'file-loader', options: { name: './assets/img/[name].[hash].[ext]', }, }, { test: /\.(woff|woff2|eot|ttf|otf)$/, loader: 'file-loader', options: { name: './assets/font/[name].[hash].[ext]', }, }, { test: /\.s[ac]ss$/i, exclude: /(node_modules|bower_components)/, use: [ // Creates `style` nodes from JS strings MiniCssExtractPlugin.loader, // Translates CSS into CommonJS 'css-loader', 'postcss-loader', // Compiles Sass to CSS 'sass-loader', ], }, ], }, };