Skip to content

Commit fb5d5e6

Browse files
author
pdallmer
committed
html loader
1 parent a5b01fb commit fb5d5e6

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Webpack configuration that creates a sfmc compatible script.
66
* array functions (map, reduce, forEach)
77
* Object functions (keys)
88
* modern JS syntax
9-
* ampScript loader
9+
* ampScriptLoader
10+
* htmlLoader
1011
* minification (optionally)
1112
## Installation
1213
`git clone https://github.com/adessoSE/ssjs-webpack.git`
@@ -51,6 +52,27 @@ in `/src/index.js`:
5152
```
5253
import ampFile from './lib/foo.amp'
5354
Write(ampFile.run());
55+
```
56+
### htmlLoader
57+
external html files can be imported and displayed.
58+
> **_NOTE:_** do not overwrite the `/templates/index.ejs`. It is required to build the SFMC compatible script.
59+
Example:
60+
create a new file `/templates/index.html`:
61+
```
62+
<html>
63+
<head>
64+
<title>Hello World!</title>
65+
</head>
66+
<body>
67+
<h1 name="msg">Hello World!</h1>
68+
</body>
69+
</html>
70+
```
71+
in `/src/index.js`:
72+
```
73+
import index from 'templates/index.html';
74+
index.display();
75+
5476
```
5577
### minification
5678
By default minification is disabled. To enable it, go to `\webpack.config.js` and set

loaders/htmlLoader.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = (input) => {
2+
return `export default({
3+
display: function(){Write(TreatAsContent('${input.replace(/\>[\r\n ]+\</g, "><")
4+
.replace(/(<.*?>)|\s+/g, (m, $1) => $1 ? $1 : ' ')
5+
.replace(/'/gi, "\\'")
6+
.trim()}'))}
7+
})`;
8+
};

webpack.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ module.exports = {
2525
target: ["web", "es3"],
2626
module: {
2727
rules: [
28+
{
29+
test: /\.(html)$/,
30+
exclude: /node_modules/,
31+
use: [
32+
{
33+
loader: "./loaders/htmlLoader.js",
34+
options: {},
35+
},
36+
],
37+
},
2838
{
2939
test: /\.(js)$/,
3040
exclude: /node_modules/,
@@ -58,6 +68,7 @@ module.exports = {
5868
alias: {
5969
polyfills: path.resolve(__dirname, "polyfills/"),
6070
lib: path.resolve(__dirname, "lib/"),
71+
templates: path.resolve(__dirname, "templates/")
6172
},
6273
},
6374
};

0 commit comments

Comments
 (0)