-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
runtime
option for the handlebars
preprocessor
- Loading branch information
Showing
15 changed files
with
121 additions
and
7 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
test/cases/loader-option-preprocessor-handlebars-runtime/expected/app.js
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file added
BIN
+1.6 KB
...ses/loader-option-preprocessor-handlebars-runtime/expected/img/fig.c6809878.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
BIN
+1.66 KB
...es/loader-option-preprocessor-handlebars-runtime/expected/img/kiwi.da3e3cc9.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
BIN
+1.72 KB
...es/loader-option-preprocessor-handlebars-runtime/expected/img/pear.6b9b072a.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions
11
test/cases/loader-option-preprocessor-handlebars-runtime/expected/index.html
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>My Title</title> | ||
<!-- load the rendered template in JS and add it into HTML in runtime --> | ||
<script src="app.js" defer="defer"></script> | ||
</head> | ||
<body> | ||
<div id="main"></div> | ||
</body> | ||
</html> |
10 changes: 10 additions & 0 deletions
10
test/cases/loader-option-preprocessor-handlebars-runtime/src/app.js
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import tmpl from './partials/content.hbs?lang=en'; | ||
|
||
const locals = { | ||
name: 'World', | ||
people: ['Alexa <Amazon>', 'Cortana <MS>', 'Siri <Apple>'], | ||
}; | ||
|
||
document.getElementById('main').innerHTML = tmpl(locals); | ||
|
||
console.log('>> app'); |
11 changes: 11 additions & 0 deletions
11
test/cases/loader-option-preprocessor-handlebars-runtime/src/index.hbs
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>{{ title }}</title> | ||
<!-- load the rendered template in JS and add it into HTML in runtime --> | ||
<script src="app.js" defer="defer"></script> | ||
</head> | ||
<body> | ||
<div id="main"></div> | ||
</body> | ||
</html> |
12 changes: 12 additions & 0 deletions
12
test/cases/loader-option-preprocessor-handlebars-runtime/src/partials/content.hbs
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<h1>Hello {{ name }}!</h1> | ||
<div>Global data: title = "{{ title }}"</div> | ||
<div>Query param: lang = "{{ lang }}"</div> | ||
|
||
<ul> | ||
{{#each people}} | ||
<li>{{this}}</li> | ||
{{/each}} | ||
</ul> | ||
|
||
<img src="@images/fig.png" srcset="@images/kiwi.png 300w, @images/pear.png 400w"> | ||
{{!-- {{TODO: add supports for include 'star'}} --}} |
2 changes: 2 additions & 0 deletions
2
test/cases/loader-option-preprocessor-handlebars-runtime/src/partials/star.hbs
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<div class="star">++ Included partial ++</div> | ||
<img src="@images/stern.svg"> |
46 changes: 46 additions & 0 deletions
46
test/cases/loader-option-preprocessor-handlebars-runtime/webpack.config.js
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const path = require('path'); | ||
const HtmlBundlerPlugin = require('@test/html-bundler-webpack-plugin'); | ||
|
||
module.exports = { | ||
mode: 'production', | ||
|
||
output: { | ||
path: path.join(__dirname, 'dist/'), | ||
}, | ||
|
||
resolve: { | ||
alias: { | ||
'@images': path.join(__dirname, '../../fixtures/images'), | ||
}, | ||
}, | ||
|
||
plugins: [ | ||
new HtmlBundlerPlugin({ | ||
entry: { | ||
index: './src/index.hbs', | ||
}, | ||
preprocessor: 'handlebars', | ||
preprocessorOptions: { | ||
//runtime: 'handlebars/runtime', // default runtime | ||
runtime: 'handlebars/dist/handlebars.runtime.min', // test custom runtime file | ||
views: ['src/partials'], | ||
partials: ['src/partials'], | ||
}, | ||
data: { | ||
title: 'My Title', | ||
}, | ||
}), | ||
], | ||
|
||
module: { | ||
rules: [ | ||
{ | ||
test: /\.(ico|png|jp?g|svg)$/, | ||
type: 'asset/resource', | ||
generator: { | ||
filename: 'img/[name].[hash:8][ext][query]', | ||
}, | ||
}, | ||
], | ||
}, | ||
}; |
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