Skip to content

Commit 6b3c53e

Browse files
committed
feat(bundler): bundle json files by default for app skeletons of cli bundler
json files are processed especially without using loader-plugin. It supports three module id forms: "a.json", "text!a.json" (or "a.json!text" for systemjs), "json!a.json" (or "a.json!json" for systemjs).
1 parent 9d4bbbe commit 6b3c53e

20 files changed

+95
-10
lines changed

lib/build/bundle.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ exports.Bundle = class {
119119
// http://requirejs.org/docs/api.html#config-bundles
120120
allIds.push(matchingPlugin.createModuleId(id));
121121
} else if (id.endsWith('.json')) {
122+
allIds.push(Utils.moduleIdWithPlugin(id, 'text', this.bundler.loaderOptions.type));
122123
allIds.push(id);
123124
// be nice to requirejs json plugin users, add json! prefix
124125
allIds.push(Utils.moduleIdWithPlugin(id, 'json', this.bundler.loaderOptions.type));

lib/build/bundled-source.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,17 @@ exports.BundledSource = class {
120120

121121
let matchingPlugin = loaderPlugins.find(p => p.matches(modulePath));
122122

123-
if (matchingPlugin) {
124-
deps = findDeps(modulePath, this.contents);
125-
this.contents = matchingPlugin.transform(moduleId, modulePath, this.contents);
126-
} else if (path.extname(modulePath).toLowerCase() === '.json') {
123+
if (path.extname(modulePath).toLowerCase() === '.json') {
124+
// support text! prefix
125+
let contents = `define(\'${Utils.moduleIdWithPlugin(moduleId, 'text', loaderType)}\',[],function(){return ${JSON.stringify(this.contents)};});\n`;
127126
// support Node.js's json module
128-
let contents = `define(\'${moduleId}\',[],function(){return JSON.parse(${JSON.stringify(this.contents)});});\n`;
127+
contents += `define(\'${moduleId}\',[\'${Utils.moduleIdWithPlugin(moduleId, 'text', loaderType)}\'],function(m){return JSON.parse(m);});\n`;
129128
// be nice to requirejs json plugin users, add json! prefix
130129
contents += `define(\'${Utils.moduleIdWithPlugin(moduleId, 'json', loaderType)}\',[\'${moduleId}\'],function(m){return m;});\n`;
131130
this.contents = contents;
131+
} else if (matchingPlugin) {
132+
deps = findDeps(modulePath, this.contents);
133+
this.contents = matchingPlugin.transform(moduleId, modulePath, this.contents);
132134
} else {
133135
deps = [];
134136

lib/commands/generate-skeletons/project-definitions/skeleton-requirejs-esnext-aspnetcore.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
"displayName": "None",
2929
"fileExtension": ".css"
3030
},
31+
"jsonProcessor": {
32+
"id": "none",
33+
"displayName": "None",
34+
"fileExtension": ".json"
35+
},
3136
"editor": {
3237
"id": "vscode",
3338
"displayName": "Visual Studio Code"

lib/commands/generate-skeletons/project-definitions/skeleton-requirejs-esnext.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
"displayName": "None",
2929
"fileExtension": ".css"
3030
},
31+
"jsonProcessor": {
32+
"id": "none",
33+
"displayName": "None",
34+
"fileExtension": ".json"
35+
},
3136
"editor": {
3237
"id": "vscode",
3338
"displayName": "Visual Studio Code"

lib/commands/generate-skeletons/project-definitions/skeleton-requirejs-typescript-aspnetcore.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
"displayName": "None",
2929
"fileExtension": ".css"
3030
},
31+
"jsonProcessor": {
32+
"id": "none",
33+
"displayName": "None",
34+
"fileExtension": ".json"
35+
},
3136
"editor": {
3237
"id": "vscode",
3338
"displayName": "Visual Studio Code"

lib/commands/generate-skeletons/project-definitions/skeleton-requirejs-typescript.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
"displayName": "None",
2929
"fileExtension": ".css"
3030
},
31+
"jsonProcessor": {
32+
"id": "none",
33+
"displayName": "None",
34+
"fileExtension": ".json"
35+
},
3136
"editor": {
3237
"id": "vscode",
3338
"displayName": "Visual Studio Code"

lib/commands/generate-skeletons/project-definitions/skeleton-systemjs-esnext-aspnetcore.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
"displayName": "None",
2929
"fileExtension": ".css"
3030
},
31+
"jsonProcessor": {
32+
"id": "none",
33+
"displayName": "None",
34+
"fileExtension": ".json"
35+
},
3136
"editor": {
3237
"id": "vscode",
3338
"displayName": "Visual Studio Code"

lib/commands/generate-skeletons/project-definitions/skeleton-systemjs-esnext.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
"displayName": "None",
2929
"fileExtension": ".css"
3030
},
31+
"jsonProcessor": {
32+
"id": "none",
33+
"displayName": "None",
34+
"fileExtension": ".json"
35+
},
3136
"editor": {
3237
"id": "vscode",
3338
"displayName": "Visual Studio Code"

lib/commands/generate-skeletons/project-definitions/skeleton-systemjs-typescript-aspnetcore.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
"displayName": "None",
2929
"fileExtension": ".css"
3030
},
31+
"jsonProcessor": {
32+
"id": "none",
33+
"displayName": "None",
34+
"fileExtension": ".json"
35+
},
3136
"editor": {
3237
"id": "vscode",
3338
"displayName": "Visual Studio Code"

lib/commands/generate-skeletons/project-definitions/skeleton-systemjs-typescript.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
"displayName": "None",
2929
"fileExtension": ".css"
3030
},
31+
"jsonProcessor": {
32+
"id": "none",
33+
"displayName": "None",
34+
"fileExtension": ".json"
35+
},
3136
"editor": {
3237
"id": "vscode",
3338
"displayName": "Visual Studio Code"

0 commit comments

Comments
 (0)