Skip to content

Commit

Permalink
html loader
Browse files Browse the repository at this point in the history
  • Loading branch information
pdallmer committed Dec 15, 2023
1 parent a5b01fb commit fb5d5e6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Webpack configuration that creates a sfmc compatible script.
* array functions (map, reduce, forEach)
* Object functions (keys)
* modern JS syntax
* ampScript loader
* ampScriptLoader
* htmlLoader
* minification (optionally)
## Installation
`git clone https://github.com/adessoSE/ssjs-webpack.git`
Expand Down Expand Up @@ -51,6 +52,27 @@ in `/src/index.js`:
```
import ampFile from './lib/foo.amp'
Write(ampFile.run());
```
### htmlLoader
external html files can be imported and displayed.
> **_NOTE:_** do not overwrite the `/templates/index.ejs`. It is required to build the SFMC compatible script.
Example:
create a new file `/templates/index.html`:
```
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<h1 name="msg">Hello World!</h1>
</body>
</html>
```
in `/src/index.js`:
```
import index from 'templates/index.html';
index.display();
```
### minification
By default minification is disabled. To enable it, go to `\webpack.config.js` and set
Expand Down
8 changes: 8 additions & 0 deletions loaders/htmlLoader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = (input) => {
return `export default({
display: function(){Write(TreatAsContent('${input.replace(/\>[\r\n ]+\</g, "><")
.replace(/(<.*?>)|\s+/g, (m, $1) => $1 ? $1 : ' ')
.replace(/'/gi, "\\'")
.trim()}'))}
})`;
};
11 changes: 11 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ module.exports = {
target: ["web", "es3"],
module: {
rules: [
{
test: /\.(html)$/,
exclude: /node_modules/,
use: [
{
loader: "./loaders/htmlLoader.js",
options: {},
},
],
},
{
test: /\.(js)$/,
exclude: /node_modules/,
Expand Down Expand Up @@ -58,6 +68,7 @@ module.exports = {
alias: {
polyfills: path.resolve(__dirname, "polyfills/"),
lib: path.resolve(__dirname, "lib/"),
templates: path.resolve(__dirname, "templates/")
},
},
};

0 comments on commit fb5d5e6

Please sign in to comment.