Skip to content

Commit

Permalink
Merge pull request #16 from tomik23/assets
Browse files Browse the repository at this point in the history
Replace file-loader -> assets
  • Loading branch information
tomickigrzegorz authored Feb 13, 2021
2 parents 08b62b1 + f93724c commit 7adad20
Show file tree
Hide file tree
Showing 30 changed files with 1,264 additions and 349 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
.htaccess
docs/
node_modules/
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ npm run prod
- [`css-loader`](https://webpack.js.org/loaders/css-loader/) - Resolves CSS imports into JS
- [`pug-loader`](https://github.com/pugjs/pug-loader/) - Pug loader template
- [`style-loader`](https://webpack.js.org/loaders/style-loader/) - Inject CSS into the DOM
- [`file-loader`](https://webpack.js.org/loaders/file-loader/) - Copy files to build folder
- [`asset modules`](https://webpack.js.org/guides/asset-modules/#resource-assets) replace ral-loader, url-loader, file-loader
- ~~[`file-loader`](https://webpack.js.org/loaders/file-loader/) - Copy files to build folder~~

### Plugins

Expand Down
42 changes: 20 additions & 22 deletions config/webpack.base.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
const path = require('path');
const HtmlWebPackPlugin = require('html-webpack-plugin');

const OUTPUT_DIR = 'docs';

// only form HtmlWebPackPlugin
const config = [
{ site: 'index', share: 'share' },
{ site: 'about', share: 'share' },
{ site: 'contact' }
];

// configure Resolve
const configureResolveAlias = () => {
return {
alias: {
'assets': path.resolve(__dirname, '../sources/images')
}
}
}

// configure Babel Loader
const configureBabelLoader = () => {
return {
Expand All @@ -42,15 +31,6 @@ const configurePugLoader = () => {
}
}

// configure Output
const configureOutput = () => {
return {
path: path.resolve(__dirname, `../${OUTPUT_DIR}`),
filename: 'vendor/js/[name].[fullhash].js',
chunkFilename: 'vendor/js/[name].[fullhash].js',
}
}

// configure HtmlWebPackPlugin
const entryHtmlPlugins = config.map(({ site, share }) => {
return new HtmlWebPackPlugin({
Expand All @@ -61,6 +41,16 @@ const entryHtmlPlugins = config.map(({ site, share }) => {
})
})

// configure Output
const configureOutput = () => {
return {
path: path.resolve(__dirname, '../docs'),
filename: 'vendor/js/[name].[fullhash].js',
// assetModuleFilename: 'images/static/[name].[hash][ext]',
publicPath: './',
}
}

module.exports = {
entry: {
index: {
Expand All @@ -77,11 +67,19 @@ module.exports = {
share: './sources/js/module/share.js'
},
output: configureOutput(),
resolve: configureResolveAlias(),
module: {
rules: [
// Images: Copy image files to build folder
// https://webpack.js.org/guides/asset-modules/#resource-assets
{
test: /\.(woff(2)?|eot|ttf|otf|svg|)$/,
type: 'asset/resource',
generator: {
filename: 'images/static/[name].[hash][ext]',
},
},
configureBabelLoader(),
configurePugLoader(),
configurePugLoader()
],
},
plugins: [
Expand Down
20 changes: 8 additions & 12 deletions config/webpack.dev.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const path = require('path');
const webpack = require('webpack');
const baseConfig = require('./webpack.base.js');
const { merge } = require('webpack-merge');
Expand All @@ -6,24 +7,19 @@ const { cssLoaders } = require('./util');
// Configure Dev Server
const configureDevServer = () => {
return {
contentBase: './sources',
contentBase: path.resolve(__dirname, '../sources'),
open: true,
port: 3000,
inline: true,
stats: "errors-only",
liveReload: true,
hot: true,
publicPath: '/',
inline: true,
watchContentBase: true,
};
};

// configure File Loader
const configureFileLoader = () => {
return {
test: /\.(jpe?g|png|gif|svg)$/i,
loader: 'file-loader'
}
}

module.exports = merge(baseConfig, {
devtool: 'eval-source-map',
mode: 'development',
target: 'web',
devServer: configureDevServer(),
Expand All @@ -37,10 +33,10 @@ module.exports = merge(baseConfig, {
...cssLoaders
],
},
configureFileLoader()
],
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
PRODUCTION: JSON.stringify(false)
}),
Expand Down
39 changes: 19 additions & 20 deletions config/webpack.prod.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const webpack = require('webpack');
const path = require('path');
const baseConfig = require('./webpack.base.js');
const { merge } = require('webpack-merge');

Expand All @@ -11,22 +12,6 @@ const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const { cssLoaders } = require('./util');

// configure File Loader
const configureFileLoader = () => {
return {
test: /\.(jpe?g|png|gif|svg)$/i,
loader: 'file-loader',
options: {
name: '[path][name].[ext]',
outputPath: (url, resourcePath, context) => {
if (/sources/.test(url)) {
return url.replace('sources', '../..');
}
}
},
}
}

// configure Optimization
const configureOptimization = () => {
return {
Expand Down Expand Up @@ -57,8 +42,17 @@ const configureSW = () => {
const configureCopy = () => {
return {
patterns: [
{ from: 'sources/assets/', to: 'assets/' },
{ from: 'sources/images/', to: 'images/' }
{
from: 'sources/assets/',
to: 'assets/'
},
{
from: 'sources/images/',
to: 'images/',
globOptions: {
ignore: ['**.svg']
}
},
]
}
};
Expand All @@ -71,11 +65,16 @@ module.exports = merge(baseConfig, {
{
test: /\.(css|sass|scss)$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: MiniCssExtractPlugin.loader,
options: {
// set path for images
publicPath: '../../',
},
},
...cssLoaders
],
},
configureFileLoader()
],
},
optimization: configureOptimization(),
Expand Down
1 change: 1 addition & 0 deletions docs/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html class="about" lang="pl" dir="ltr"><head><link rel="dns-prefetch" href="//google-analytics.com"><link rel="preconnect" href="//fonts.gstatic.com/" crossorigin><meta charset="utf-8"><meta http-equiv="x-ua-compatible" content="ie=edge"><meta name="description" content="description - about"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="index,follow"><meta name="theme-color" content="#ffffff"><meta name="msapplication-navbutton-color" content="#ffffff"><meta name="apple-mobile-web-app-status-bar-style" content="#ffffff"><meta content="telephone=no" name="format-detection"><title>title - about</title><link rel="manifest" href="/assets/manifest.json"><link rel="icon" type="image/x-icon" href="/favicon.ico"><script defer="defer" src="./vendor/js/about.2e9dd730285391ac05be.js"></script><script defer="defer" src="./vendor/js/share.2e9dd730285391ac05be.js"></script><link href="./vendor/css/about.2e9dd730285391ac05be.css" rel="stylesheet"></head><body><div class="nav"><a href="./" title="index">index</a><a class="active" href="./about.html" title="about me">about me</a><a href="./contact.html" title="CONTACT">contact</a></div><h1>ABOUT ME</h1><img class="responsive" src="images/about.jpg"></body></html>
94 changes: 94 additions & 0 deletions docs/assets/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^xxxxxxx.pl [NC]
RewriteRule ^(.*)$ http://xxxxxxx.pl/$1 [L,R=301]

<IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml

# Remove browser bugs (only needed for really old browsers)
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
</IfModule>

<IfModule mod_expires.c>
ExpiresActive on

# Perhaps better to whitelist expires rules? Perhaps.
ExpiresDefault "access plus 1 month"

# cache.appcache needs re-requests in FF 3.6 (thx Remy ~Introducing HTML5)
ExpiresByType text/cache-manifest "access plus 0 seconds"



# Your document html
ExpiresByType text/html "access plus 1 month"

# Data
ExpiresByType text/xml "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType application/json "access plus 0 seconds"

# RSS feed
ExpiresByType application/rss+xml "access plus 1 hour"

# Favicon (cannot be renamed)
ExpiresByType image/x-icon "access plus 1 year"

# Media: images, video, audio
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType video/ogg "access plus 1 year"
ExpiresByType audio/ogg "access plus 1 year"
ExpiresByType video/mp4 "access plus 1 year"
ExpiresByType video/webm "access plus 1 year"

# HTC files (css3pie)
ExpiresByType text/x-component "access plus 1 month"

# Webfonts
ExpiresByType font/truetype "access plus 1 year"
ExpiresByType font/opentype "access plus 1 year"
ExpiresByType application/x-font-woff "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType application/vnd.ms-fontobject "access plus 1 year"

# CSS and JavaScript
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType text/javascript "access plus 1 year"

<IfModule mod_headers.c>
Header append Cache-Control "public"
Header unset ETag
FileETag None
</IfModule>

</IfModule>
21 changes: 21 additions & 0 deletions docs/assets/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "xxxxxxx",
"short_name": "xxxxxxx",
"icons": [
{
"src": "/images/static/app_192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/images/static/app_512x512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"start_url": "/index.html",
"display": "standalone",
"theme_color": "#FFFFFF",
"background_color": "#FFFFFF",
"orientation": "portrait"
}
1 change: 1 addition & 0 deletions docs/contact.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html class="contact" lang="pl" dir="ltr"><head><link rel="dns-prefetch" href="//google-analytics.com"><link rel="preconnect" href="//fonts.gstatic.com/" crossorigin><meta charset="utf-8"><meta http-equiv="x-ua-compatible" content="ie=edge"><meta name="description" content="description - contact"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="index,follow"><meta name="theme-color" content="#ffffff"><meta name="msapplication-navbutton-color" content="#ffffff"><meta name="apple-mobile-web-app-status-bar-style" content="#ffffff"><meta content="telephone=no" name="format-detection"><title>title - contact</title><link rel="manifest" href="/assets/manifest.json"><link rel="icon" type="image/x-icon" href="/favicon.ico"><script defer="defer" src="./vendor/js/contact.2e9dd730285391ac05be.js"></script><link href="./vendor/css/contact.2e9dd730285391ac05be.css" rel="stylesheet"></head><body><div class="nav"><a href="./" title="index">index</a><a href="./about.html" title="about me">about me</a><a class="active" href="./contact.html" title="CONTACT">contact</a></div><h1>CONTACT</h1><img class="responsive" src="images/contact.jpg"></body></html>
Binary file added docs/images/about.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/contact.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/index.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/static/app_192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/static/app_512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/images/static/bamboo-logo.4d42886c6b116c786dd6.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html class="index" lang="pl" dir="ltr"><head><link rel="dns-prefetch" href="//google-analytics.com"><link rel="preconnect" href="//fonts.gstatic.com/" crossorigin><meta charset="utf-8"><meta http-equiv="x-ua-compatible" content="ie=edge"><meta name="description" content="description - index"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="index,follow"><meta name="theme-color" content="#ffffff"><meta name="msapplication-navbutton-color" content="#ffffff"><meta name="apple-mobile-web-app-status-bar-style" content="#ffffff"><meta content="telephone=no" name="format-detection"><title>title - index</title><link rel="manifest" href="/assets/manifest.json"><link rel="icon" type="image/x-icon" href="/favicon.ico"><script defer="defer" src="./vendor/js/index.2e9dd730285391ac05be.js"></script><script defer="defer" src="./vendor/js/share.2e9dd730285391ac05be.js"></script><link href="./vendor/css/index.2e9dd730285391ac05be.css" rel="stylesheet"></head><body><div class="nav"><a class="active" href="./" title="index">index</a><a href="./about.html" title="about me">about me</a><a href="./contact.html" title="CONTACT">contact</a></div><h1>INDEX</h1><img class="responsive" src="images/index.jpg"></body></html>
1 change: 1 addition & 0 deletions docs/service-worker.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/vendor/css/about.2e9dd730285391ac05be.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/vendor/css/contact.2e9dd730285391ac05be.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/vendor/css/index.2e9dd730285391ac05be.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/vendor/js/about.2e9dd730285391ac05be.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/vendor/js/contact.2e9dd730285391ac05be.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!function(){"use strict";console.log("CONTACT")}();
1 change: 1 addition & 0 deletions docs/vendor/js/index.2e9dd730285391ac05be.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7adad20

Please sign in to comment.