@norith/glimmerx-webpack-loader 1.0.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.
Files changed (2) hide show
  1. package/index.js +68 -0
  2. package/package.json +32 -0
package/index.js ADDED
@@ -0,0 +1,68 @@
1
+ require('validate-peer-dependencies')(__dirname);
2
+
3
+ const { preprocessEmbeddedTemplates } = require('babel-plugin-htmlbars-inline-precompile');
4
+
5
+ const { getOptions } = require('loader-utils');
6
+ const { validate } = require('schema-utils');
7
+
8
+ const getTemplateLocalsRequirePath = require.resolve('@glimmer/syntax');
9
+
10
+ const schema = {
11
+ type: 'object',
12
+ properties: {
13
+ test: {
14
+ type: 'string',
15
+ },
16
+ },
17
+ };
18
+
19
+ const TEMPLATE_TAG_CONFIG = {
20
+ getTemplateLocalsRequirePath,
21
+ getTemplateLocalsExportPath: 'getTemplateLocals',
22
+
23
+ templateTag: 'template',
24
+ templateTagReplacement: 'GLIMMER_TEMPLATE',
25
+
26
+ includeSourceMaps: true,
27
+ includeTemplateTokens: true,
28
+ };
29
+
30
+ const TEMPLATE_LITERAL_CONFIG = {
31
+ getTemplateLocalsRequirePath,
32
+ getTemplateLocalsExportPath: 'getTemplateLocals',
33
+
34
+ importIdentifier: 'hbs',
35
+ importPath: '@glimmerx/component',
36
+
37
+ includeSourceMaps: true,
38
+ includeTemplateTokens: true,
39
+ };
40
+
41
+ module.exports = function (source) {
42
+ const options = getOptions(this);
43
+
44
+ validate(schema, options, {
45
+ name: 'Glimmer Embedded Template Loader',
46
+ baseDataPath: 'options',
47
+ });
48
+
49
+ let filename = this._module.resource;
50
+
51
+ if (filename.match(/\.(js|ts)$/)) {
52
+ let { output } = preprocessEmbeddedTemplates(
53
+ source,
54
+ Object.assign({ relativePath: filename }, TEMPLATE_LITERAL_CONFIG)
55
+ );
56
+
57
+ return output;
58
+ } else if (filename.match(/\.(gjs|gts)$/)) {
59
+ let { output } = preprocessEmbeddedTemplates(
60
+ source,
61
+ Object.assign({ relativePath: filename }, TEMPLATE_TAG_CONFIG)
62
+ );
63
+
64
+ return output;
65
+ }
66
+
67
+ return source;
68
+ };
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@norith/glimmerx-webpack-loader",
3
+ "version": "1.0.0",
4
+ "description": "GlimmerX Webpack Loader",
5
+ "repository": "https://github.com/snorith/glimmer-experimental",
6
+ "author": "Tom Dale <tom@tomdale.net>",
7
+ "license": "MIT",
8
+ "private": false,
9
+ "scripts": {
10
+ "test": "mocha -r esm"
11
+ },
12
+ "dependencies": {
13
+ "@glimmer/syntax": "^0.92.0",
14
+ "validate-peer-dependencies": "^1.1.0",
15
+ "loader-utils": "2.0.0",
16
+ "schema-utils": "3.0.0"
17
+ },
18
+ "peerDependencies": {
19
+ "@norith/glimmerx-babel-preset": "1.0.0",
20
+ "babel-plugin-htmlbars-inline-precompile": "^5.2.1"
21
+ },
22
+ "devDependencies": {
23
+ "babel-plugin-tester": "^6.4.0",
24
+ "chai": "^4.2.0",
25
+ "esm": "^3.2.25",
26
+ "mocha": "^6.2.0"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public",
30
+ "registry": "https://registry.npmjs.org"
31
+ }
32
+ }