ncounter/webpack.common.js

92 lines
2.9 KiB
JavaScript
Raw Normal View History

2020-02-06 12:27:58 -05:00
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const GoogleFontsPlugin = require('@beyonk/google-fonts-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const ServiceWorkerWebpackPlugin = require('serviceworker-webpack-plugin');
const LicensePlugin = require('webpack-license-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
2020-02-06 12:27:58 -05:00
2020-03-03 22:12:11 -05:00
const now = new Date();
2020-03-03 22:13:45 -05:00
const year = now.getFullYear().toString();
2020-03-03 22:12:11 -05:00
const releaseDate = now.getFullYear() + "-" + (now.getMonth() + 1).toString().padStart(2, '0') + "-" + now.getDate().toString().padStart(2, '0');
2020-02-06 12:27:58 -05:00
module.exports = {
entry: './src/index.js',
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
title: 'NCounter',
template: 'src/index.html'
2020-02-06 12:27:58 -05:00
}),
new GoogleFontsPlugin({
fonts: [
{ family: "Material Icons" }
],
local: false
}),
new ServiceWorkerWebpackPlugin({
entry: path.join(__dirname, 'src/sw.js'),
2020-02-06 14:45:09 -05:00
publicPath: './'
}),
new LicensePlugin(),
2020-03-07 10:48:15 -05:00
new CopyWebpackPlugin([
{
from: 'src/icon/*.png', to: 'icons', flatten: true
},
{
from: 'src/icon/safari-pinned-tab.svg', to: 'icons'
},
{
from: 'src/icon/favicon.ico', to: 'icons'
2020-03-07 10:48:15 -05:00
},
{
from: 'src/icon/site.webmanifest', to: 'icons'
},
{
2020-03-07 10:48:15 -05:00
from: 'src/icon/browserconfig.xml', to: 'icons'
}
2020-03-07 10:48:15 -05:00
])
2020-02-06 12:27:58 -05:00
],
output: {
filename: 'index.js',
path: path.resolve(__dirname, 'dist')
},
module: {
rules: [
{
test: /\.html$/,
loader: 'html-loader',
options: {
interpolate: true
}
},
2020-02-06 12:27:58 -05:00
{
test: /\.svelte$/,
exclude: /node_modules/,
use: [
'svelte-loader',
{
loader: 'string-replace-loader',
options: {
multiple: [
2020-03-03 22:12:11 -05:00
{ search: '|BUILD_YEAR|', replace: year },
{ search: '|BUILD_DATE|', replace: releaseDate}
]
}
}
]
2020-02-06 12:27:58 -05:00
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
},
{
test: /\.png$/,
loader: 'file-loader'
2020-02-06 12:27:58 -05:00
}
]
},
}