-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from webdiscus/main
Using the new html-bundler-webpack-plugin to fix all issues
- Loading branch information
Showing
6 changed files
with
88 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
{ | ||
"title": "Einige Titel in deutscher Sprache verfasst (Deutschland)" | ||
"title": "Einige Titel in deutscher Sprache verfasst (Deutschland)", | ||
"language": "Deutsch", | ||
"my_language": "Meine Sprache" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
{ | ||
"title": "Some title written in English (Great Britain)" | ||
"title": "Some title written in English (Great Britain)", | ||
"language": "English", | ||
"my_language": "My language" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
(function () { | ||
console.log("<%= title %>"); | ||
// note: the `locales` is the stringified JSON from <script>var locales = {title:'...', ...};</script> tag in HTML | ||
console.log("title: ", locales.title, { locales }); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,76 @@ | ||
const path = require('path'); | ||
const HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
const HtmlBundlerPlugin = require('html-bundler-webpack-plugin'); | ||
|
||
const languages = { | ||
"de-DE": require("./locales/de-DE.json"), | ||
"en-GB": require("./locales/en-GB.json"), | ||
}; | ||
|
||
module.exports = Object.keys(languages).map(language => { | ||
return { | ||
entry: './src/index.js', | ||
output: { | ||
path: path.join(__dirname, `/dist${language === "en-GB" ? "" : `/${language}`}`), | ||
filename: 'index.js', | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.html$/, | ||
use: ["html-loader"] | ||
module.exports = { | ||
output: { | ||
path: path.join(__dirname, '/dist'), | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.css$/i, | ||
use: ["css-loader"], | ||
}, | ||
{ | ||
test: /\.(ico|png|jp?g|webp|svg)$/, | ||
type: 'asset/resource', | ||
generator: { | ||
filename: 'img/[name].[hash:8][ext][query]', | ||
}, | ||
}, | ||
], | ||
}, | ||
plugins: [ | ||
new HtmlBundlerPlugin({ | ||
// define templates here | ||
// you can generate this `entry` object instead of multiple configurations for HtmlWebpackPlugin | ||
entry: { | ||
index : { // => dist/index.html | ||
import: './public/index.html', | ||
data: { | ||
// pass variables into the template | ||
title: languages['en-GB'].title, | ||
// - OR - you can pass completelly all translates into template, then use in template as `i18n.title` | ||
i18n: languages['en-GB'], | ||
// pass data into inline JS, that are accessible from a JS file | ||
locales: JSON.stringify(languages['en-GB']), | ||
} | ||
}, | ||
{ | ||
test: /\.css$/i, | ||
use: ["style-loader", "css-loader"], | ||
'de-DE/index' : { // => dist/de-DE/index.html | ||
import: './public/index.html', | ||
data: { | ||
// pass variables into the template | ||
title: languages['de-DE'].title, | ||
// - OR - you can pass completelly all translates into template, then use in template as `i18n.title` | ||
i18n: languages['de-DE'], | ||
// pass data into inline JS, that are accessible from a JS file | ||
locales: JSON.stringify(languages['de-DE']), | ||
} | ||
}, | ||
], | ||
}, | ||
js: { | ||
// JS output filename | ||
filename: '[name].[contenthash:8].js' | ||
}, | ||
css: { | ||
// CSS output filename | ||
filename: '[name].[contenthash:8].css', | ||
//inline: 'true', // you can inline CSS into HTML | ||
} | ||
}), | ||
], | ||
devServer: { | ||
static: path.join(__dirname, 'dist'), | ||
watchFiles: { | ||
paths: ['src/**/*.*'], | ||
options: { | ||
usePolling: true, | ||
}, | ||
}, | ||
plugins: [ | ||
new HtmlWebpackPlugin({ | ||
template: './public/index.html', | ||
minify: false, | ||
hash: true, | ||
templateParameters: { | ||
title: languages[language].title | ||
} | ||
}) | ||
] | ||
}; | ||
}); | ||
}, | ||
} |