-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for handlebars helpers in compile mode
- Loading branch information
Showing
18 changed files
with
195 additions
and
20 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
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
7 changes: 7 additions & 0 deletions
7
test/cases/_preprocessor/js-tmpl-hbs-compile-helpers/.editorconfig
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,7 @@ | ||
root = true | ||
|
||
[*.html] | ||
insert_final_newline = true | ||
|
||
[*.hbs] | ||
insert_final_newline = true |
1 change: 1 addition & 0 deletions
1
test/cases/_preprocessor/js-tmpl-hbs-compile-helpers/expected/app.js
Large diffs are not rendered by default.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
test/cases/_preprocessor/js-tmpl-hbs-compile-helpers/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>Home</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="app"></div> | ||
</body> | ||
</html> |
2 changes: 2 additions & 0 deletions
2
test/cases/_preprocessor/js-tmpl-hbs-compile-helpers/src/app.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 @@ | ||
<p>Hello {{#bold}}{{helloName}}{{/bold}}!</p> | ||
{{> 'footer'}} |
9 changes: 9 additions & 0 deletions
9
test/cases/_preprocessor/js-tmpl-hbs-compile-helpers/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,9 @@ | ||
import tmpl from './app.hbs'; | ||
|
||
const locals = { | ||
helloName: 'World', | ||
}; | ||
|
||
document.getElementById('app').innerHTML = tmpl(locals); | ||
|
||
console.log('>> app'); |
11 changes: 11 additions & 0 deletions
11
test/cases/_preprocessor/js-tmpl-hbs-compile-helpers/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>Home</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="app"></div> | ||
</body> | ||
</html> |
1 change: 1 addition & 0 deletions
1
test/cases/_preprocessor/js-tmpl-hbs-compile-helpers/src/partials/footer.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 @@ | ||
<div>-= FOOTER =-</div> |
52 changes: 52 additions & 0 deletions
52
test/cases/_preprocessor/js-tmpl-hbs-compile-helpers/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,52 @@ | ||
const path = require('path'); | ||
const HtmlBundlerPlugin = require('@test/html-bundler-webpack-plugin'); | ||
const Handlebars = require('handlebars'); | ||
|
||
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: { | ||
//knownHelpersOnly: false, | ||
// define helpers manually | ||
helpers: { | ||
// WARNING: don't use the arrow function with `this` otherwise webpack compile `this` into `void 0` | ||
//bold: (options) => new Handlebars.SafeString(`<strong>${options.fn(this)}</strong>`), | ||
|
||
bold(options) { | ||
return new Handlebars.SafeString(`<strong>${options.fn(this)}</strong>`); | ||
}, | ||
}, | ||
partials: ['src/partials'], | ||
}, | ||
}), | ||
], | ||
|
||
module: { | ||
rules: [ | ||
{ | ||
test: /\.(png|svg|jpe?g|webp)$/i, | ||
type: 'asset/resource', | ||
generator: { | ||
filename: 'img/[name].[hash:8][ext]', | ||
}, | ||
}, | ||
], | ||
}, | ||
}; |
2 changes: 1 addition & 1 deletion
2
test/cases/_preprocessor/js-tmpl-hbs-compile-partials/expected/app.js
Large diffs are not rendered by default.
Oops, something went wrong.
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
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