Skip to content
This repository was archived by the owner on May 16, 2024. It is now read-only.

Commit fb2882b

Browse files
committed
content update
1 parent 1b7761e commit fb2882b

File tree

1 file changed

+129
-4
lines changed

1 file changed

+129
-4
lines changed

README.md

+129-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,122 @@ EJS loader for [webpack](http://webpack.github.io/). Uses [ejs](https://github.c
66

77
`npm install ejs-webpack-loader`
88

9-
## Usage
9+
## Config Setup examples as module loader
10+
11+
ejs example
12+
```ejs
13+
<!DOCTYPE html>
14+
<html lang="en">
15+
<head>
16+
<meta charset="UTF-8">
17+
<title><%= title %></title>
18+
</head>
19+
<body>
20+
<p><%= someVar %></p>
21+
</body>
22+
</html>
23+
```
24+
25+
webpack.config.js
26+
27+
``` javascript
28+
29+
const path = require('path');
30+
31+
const config = {
32+
output: {
33+
filename: 'my-first-webpack.bundle.js'
34+
},
35+
module: {
36+
rules: [
37+
{
38+
test: /\.ejs$/,
39+
use: [
40+
{
41+
loader: "ejs-webpack-loader",
42+
options: {
43+
data: {title: "New Title", someVar:"hello world"},
44+
htmlmin: true
45+
}
46+
}
47+
]
48+
}
49+
]
50+
}
51+
};
52+
53+
```
54+
55+
## Config Setup examples with separate extractor
56+
57+
``` javascript
58+
59+
const path = require('path');
60+
61+
const config = {
62+
entry: [
63+
'./src/index.ejs',
64+
'./src/main.ejs',
65+
]
66+
output: {
67+
filename: 'my-first-webpack.bundle.js'
68+
},
69+
module: {
70+
rules: [
71+
{
72+
test: /\.ejs$/,
73+
use: [
74+
{
75+
loader: 'file-loader',
76+
options: {
77+
name: '[name].html',
78+
context: './src/',
79+
outputPath: '/'
80+
}
81+
},
82+
{
83+
loader: 'extract-loader'
84+
},
85+
{
86+
loader: "ejs-webpack-loader",
87+
{
88+
data: {title: "New Title", someVar:"hello world"},
89+
htmlmin: true
90+
}
91+
}
92+
]
93+
}
94+
]
95+
}
96+
};
97+
98+
```
99+
100+
## Config Setup examples (via HtmlWebpackPlugin)
101+
102+
``` javascript
103+
104+
const path = require('path');
105+
106+
const config = {
107+
output: {
108+
filename: 'my-first-webpack.bundle.js'
109+
},
110+
module: {
111+
...
112+
},
113+
plugin: {
114+
new HtmlWebpackPlugin({
115+
template: '!!ejs-webpack-loader!src/index.ejs'
116+
})
117+
}
118+
};
119+
120+
module.exports = config;
121+
122+
```
123+
124+
## EJS Example
10125

11126
[Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html)
12127

@@ -36,9 +151,19 @@ Following options can be specified in query:
36151

37152
```javascript
38153
module: {
39-
loaders: [
40-
{test: /\.ejs$/, loader: 'ejs-compiled?htmlmin'} // enable here
41-
]
154+
rules: [
155+
{
156+
test: /\.ejs$/,
157+
use: [
158+
{
159+
loader: "ejs-webpack-loader",
160+
options: {
161+
htmlmin: true
162+
}
163+
}
164+
]
165+
}
166+
]
42167
}
43168
```
44169

0 commit comments

Comments
 (0)