ncounter.git

git clone https://git.crispbyte.dev/ncounter.git

CheddarCrisp  ·  2024-04-12

webpack.common.js

 1const path = require('path');
 2const HtmlWebpackPlugin = require('html-webpack-plugin');
 3const { CleanWebpackPlugin } = require('clean-webpack-plugin');
 4const LicensePlugin = require('webpack-license-plugin');
 5const CopyWebpackPlugin = require('copy-webpack-plugin');
 6
 7const now = new Date();
 8const year = now.getFullYear().toString();
 9const releaseDate = now.getFullYear() + "-" + (now.getMonth() + 1).toString().padStart(2, '0') + "-" + now.getDate().toString().padStart(2, '0');
10
11module.exports = {
12    entry: {
13        index: './src/index.js',
14        sw: './src/sw.js'
15    },
16    plugins: [
17        new CleanWebpackPlugin(),
18        new HtmlWebpackPlugin({
19            excludeChunks: ['sw'],
20            template: 'src/index.html'
21        }),
22        new LicensePlugin(),
23        new CopyWebpackPlugin({
24            patterns: [
25                {
26                    from: 'src/icon/*.png', to: path.resolve(__dirname, 'dist', 'icons', '[name][ext]')
27                },
28                {
29                    from: 'src/icon/safari-pinned-tab.svg', to: 'icons'
30                },
31                {
32                    from: 'src/icon/favicon.ico', to: 'icons'
33                },
34                {
35                    from: 'src/icon/site.webmanifest', to: 'icons'
36                },
37                {
38                    from: 'src/icon/browserconfig.xml', to: 'icons'
39                }
40            ]
41        })
42    ],
43    output: {
44        filename: '[name].js',
45        path: path.resolve(__dirname, 'dist')
46    },
47    module: {
48        rules: [
49            {
50                test: /\.svelte$/,
51                exclude: /node_modules/,
52                use: [
53                    'svelte-loader',
54                    {
55                        loader: 'string-replace-loader',
56                        options: {
57                            multiple: [
58                                { search: '|BUILD_YEAR|', replace: year },
59                                { search: '|BUILD_DATE|', replace: releaseDate}
60                            ]
61                        }
62                    }
63                ]
64            },
65            {
66                test: /\.css$/,
67                use: [
68                    'style-loader',
69                    'css-loader'
70                ]
71            },
72            {
73                test: /\.png$/,
74                loader: 'file-loader'
75            }
76        ]
77    },
78    resolve: {
79      conditionNames: ['svelte']  
80    },
81}