@yamato-daiwa/universal-reactive-webpack-loader 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +91 -0
- package/index.js +32 -6
- package/package.json +6 -6
package/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Yamato Daiwa Universal Reactive - Webpack Loader
|
|
2
|
+
|
|
3
|
+
The Webpack loader for [Yamato Daiwa Universal Reactive](https://www.npmjs.com/package/@yamato-daiwa/universal-reactive),
|
|
4
|
+
the object-oriented programming-based library for the frontend Web+ development alternative to React, Vue, Svelte and
|
|
5
|
+
the like.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
npm i @yamato-daiwa/universal-reactive-templates-compiler @yamato-daiwa/universal-reactive -E
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Please make sure that you are installing the above dependencies with common version.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## Setup
|
|
18
|
+
### Usage of Pug Pre-processor Only Under the Yamato Daiwa Universal Reactive
|
|
19
|
+
|
|
20
|
+
```javascript
|
|
21
|
+
{
|
|
22
|
+
|
|
23
|
+
// ... Usual Webpack configuration
|
|
24
|
+
|
|
25
|
+
module: {
|
|
26
|
+
rules: [
|
|
27
|
+
|
|
28
|
+
{
|
|
29
|
+
test: /\.ydur\.pug$/u,
|
|
30
|
+
loader: "@yamato-daiwa/universal-reactive-webpack-loader"
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
// ... Other loaders
|
|
34
|
+
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Usage of Pug pre-processor with Webpack for Different Purposes
|
|
42
|
+
|
|
43
|
+
In this case, you must to decide the rules how webpack will select the appropriate loader.
|
|
44
|
+
Here is just the example.
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
{
|
|
48
|
+
|
|
49
|
+
// ... Usual Webpack configuration
|
|
50
|
+
|
|
51
|
+
module: {
|
|
52
|
+
rules: [
|
|
53
|
+
{
|
|
54
|
+
test: /\.pug$/u,
|
|
55
|
+
oneOf: [
|
|
56
|
+
|
|
57
|
+
{
|
|
58
|
+
resourceQuery: /^\?vue/u,
|
|
59
|
+
loader: "@webdiscus/pug-loader",
|
|
60
|
+
options: { mode: "html" }
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
{
|
|
64
|
+
test: /\.renderer\.pug$/u,
|
|
65
|
+
loader: "@webdiscus/pug-loader",
|
|
66
|
+
options: { mode: "compile" }
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
{
|
|
70
|
+
test: /\.ydur\.pug$/u,
|
|
71
|
+
loader: "@yamato-daiwa/universal-reactive-webpack-loader",
|
|
72
|
+
options: {
|
|
73
|
+
debug: true
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
{
|
|
78
|
+
loader: "@webdiscus/pug-loader",
|
|
79
|
+
options: { mode: "render" }
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
]
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
// ... Other loaders
|
|
86
|
+
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
}
|
|
91
|
+
```
|
package/index.js
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
const PugLexer = require("pug-lexer");
|
|
2
2
|
const generatePugAST = require("pug-parser");
|
|
3
|
-
const {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
const { TemplatesCompiler: YamatoDaiwaUniversalReactiveTemplatesCompiler } =
|
|
4
|
+
require("@yamato-daiwa/universal-reactive-templates-compiler");
|
|
5
|
+
const formatJavaScript = require("js-beautify").js;
|
|
6
|
+
const { validate } = require("schema-utils");
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
const schema = {
|
|
10
|
+
type: "object",
|
|
11
|
+
properties: {
|
|
12
|
+
debug: {
|
|
13
|
+
type: "boolean"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
};
|
|
7
17
|
|
|
8
18
|
module.exports = function(sourceCode) {
|
|
9
19
|
|
|
20
|
+
const options = this.getOptions();
|
|
10
21
|
const callback = this.async();
|
|
11
22
|
|
|
12
23
|
try {
|
|
@@ -15,10 +26,25 @@ module.exports = function(sourceCode) {
|
|
|
15
26
|
|
|
16
27
|
const PugAST = generatePugAST(tokens, { src: sourceCode });
|
|
17
28
|
|
|
29
|
+
if (options.debug) {
|
|
30
|
+
console.log(
|
|
31
|
+
"@yamato-daiwa/universal-reactive-webpack-loader, formatted output:\n" +
|
|
32
|
+
formatJavaScript(
|
|
33
|
+
`export default ${ YamatoDaiwaUniversalReactiveTemplatesCompiler.generateCode(PugAST) };`,
|
|
34
|
+
{
|
|
35
|
+
indent_size: 2,
|
|
36
|
+
end_with_newline: true,
|
|
37
|
+
eol: "\n",
|
|
38
|
+
brace_style: "collapse"
|
|
39
|
+
}
|
|
40
|
+
)
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
18
44
|
callback(
|
|
19
45
|
null,
|
|
20
|
-
`
|
|
21
|
-
|
|
46
|
+
`export default ${ YamatoDaiwaUniversalReactiveTemplatesCompiler.generateCode(PugAST) };`
|
|
47
|
+
);
|
|
22
48
|
|
|
23
49
|
} catch (error) {
|
|
24
50
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yamato-daiwa/universal-reactive-webpack-loader",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "The webpack loader for Pug templates of \"@yamato-daiwa/universal-reactive\", the frontend library.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"webpack",
|
|
@@ -28,14 +28,14 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/TokugawaTakeshi/Yamato-Daiwa-Universal-Reactive",
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"@yamato-daiwa/universal-reactive-templates-compiler": "0.0.0"
|
|
31
|
+
"@yamato-daiwa/universal-reactive-templates-compiler": "0.1.0",
|
|
32
|
+
"webpack": "^5.0.0"
|
|
34
33
|
},
|
|
35
34
|
"dependencies": {
|
|
36
|
-
"@yamato-daiwa/universal-reactive-templates-compiler": "0.
|
|
35
|
+
"@yamato-daiwa/universal-reactive-templates-compiler": "0.1.0",
|
|
37
36
|
"pug-error": "2.1.0",
|
|
38
37
|
"pug-lexer": "5.0.1",
|
|
39
|
-
"pug-parser": "6.0.0"
|
|
38
|
+
"pug-parser": "6.0.0",
|
|
39
|
+
"js-beautify": "1.15.4"
|
|
40
40
|
}
|
|
41
41
|
}
|