ncounter/webpack.common.js

81 lines
2.5 KiB
JavaScript
Raw Permalink Normal View History

2020-02-06 12:27:58 -05:00
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-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: {
index: './src/index.js',
sw: './src/sw.js'
},
2020-02-06 12:27:58 -05:00
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
excludeChunks: ['sw'],
template: 'src/index.html'
2020-02-06 12:27:58 -05:00
}),
new LicensePlugin(),
new CopyWebpackPlugin({
patterns: [
{
from: 'src/icon/*.png', to: path.resolve(__dirname, 'dist', 'icons', '[name][ext]')
},
{
from: 'src/icon/safari-pinned-tab.svg', to: 'icons'
},
{
from: 'src/icon/favicon.ico', to: 'icons'
},
{
from: 'src/icon/site.webmanifest', to: 'icons'
},
{
from: 'src/icon/browserconfig.xml', to: 'icons'
}
]
})
2020-02-06 12:27:58 -05:00
],
output: {
filename: '[name].js',
2020-02-06 12:27:58 -05:00
path: path.resolve(__dirname, 'dist')
},
module: {
rules: [
{
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
}
]
},
resolve: {
conditionNames: ['svelte']
},
2020-02-06 12:27:58 -05:00
}