123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- "use strict";
- const path = require('path');
- const glob = require('glob');
- const { ProvidePlugin } = require("webpack");
- const CopyPlugin = require("copy-webpack-plugin");
- const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
- const ESLintPlugin = require("eslint-webpack-plugin");
- const MiniCssExtractPlugin = require("mini-css-extract-plugin");
- const misago = path.resolve(__dirname, "../misago/static/misago/");
- const modules = path.resolve(__dirname, "node_modules");
- const getEntries = () => {
- const entry = ["./src/index.js"];
- glob.sync("./src/initializers/**/*.js").forEach((path) => entry.push(path));
- return entry;
- };
- module.exports = (env, argv) => {
- const isProduction = argv.mode === "production";
- return {
- mode: isProduction ? "production" : "development",
- devtool: "source-map",
- entry: {
- misago: getEntries(),
- },
- output: {
- path: path.resolve(misago, "js"),
- filename: "[name].js",
- },
- optimization: {
- minimize: isProduction,
- minimizer: [
- "...",
- new CssMinimizerPlugin(),
- ],
- splitChunks: {
- cacheGroups: {
- vendor: {
- test: /[\\/]node_modules[\\/]/,
- name: "vendor",
- chunks: "all",
- },
- hljs: {
- test: /[\\/]highlight[\\/]/,
- name: "hljs",
- chunks: "all",
- },
- },
- },
- },
- module: {
- rules: [
- {
- test: /\.jsx?$/,
- exclude: /node_modules/,
- use: {
- loader: "babel-loader",
- options: {
- cacheDirectory: true,
- cacheCompression: false,
- envName: isProduction ? "production" : "development",
- },
- },
- },
- {
- test: /\.less$/i,
- use: [
- "style-loader",
- "css-loader",
- "less-loader",
- ],
- use: [MiniCssExtractPlugin.loader, "css-loader", "less-loader"],
- },
- {
- test: /\.(woff|ttf|eot|woff2)/,
- type: "asset/resource",
- generator: {
- filename: "../fonts/[name][ext]"
- }
- },
- ],
- },
- resolve: {
- alias: {
- misago: path.resolve(__dirname, "src"),
- "at-js": path.resolve(modules, "at.js/dist/js/jquery.atwho.js"),
- "jquery-caret": path.resolve(modules, "jquery.caret/dist/jquery.caret.js"),
- "waypoints": path.resolve(modules, "waypoints/lib/jquery.waypoints.js"),
- highlight: path.resolve(__dirname, "highlight/highlight.js"),
- },
- extensions: [".js", ".jsx"],
- },
- plugins: [
- new ESLintPlugin(
- {
- extensions: ["js", "jsx"],
- files: "./src/"
- },
- ),
- new CopyPlugin(
- {
- patterns: [
- {
- from: "./static",
- to: misago,
- },
- {
- from: "./node_modules/zxcvbn/dist",
- to: path.resolve(misago, "js"),
- },
- ],
- }
- ),
- new MiniCssExtractPlugin(
- {
- filename: "../css/misago.css",
- }
- ),
- new ProvidePlugin({
- $: "jquery",
- "window.$": "jquery",
- jQuery: "jquery",
- "window.jQuery": "jquery",
- moment: "moment",
- "window.moment": "moment",
- }),
- ],
- watchOptions: {
- ignored: "**/node_modules",
- poll: 2000, // Check for changes every two seconds
- stdin: true,
- },
- };
- };
|