From 432a34e87f1735da251c31c1f6de0cb73138adca Mon Sep 17 00:00:00 2001 From: Dylan Piercey Date: Mon, 24 Feb 2020 11:44:48 -0800 Subject: [PATCH] Marko 5 support (#24) * feat: add support for Marko 5 --- package-lock.json | 11 +++- package.json | 3 +- .../__snapshots__/server--main.js | 13 ++--- .../basic-template/__snapshots__/main.js | 1 - .../__snapshots__/server--main.js | 29 ++++------- .../__snapshots__/browser-A--test_YDNP.A.js | 1 - .../__snapshots__/browser-B--test_YDNP.B.js | 1 - .../__snapshots__/browser-C--test_YDNP.C.js | 1 - .../__snapshots__/server--main.js | 16 +++--- .../__snapshots__/browser--test_nzzJ.js | 1 - .../__snapshots__/server--main.js | 16 +++--- .../with-css-extract/__snapshots__/main.js | 1 - .../fixtures/with-css/__snapshots__/main.js | 1 - src/loader/get-asset-code.ts | 4 +- src/loader/head-transformer.ts | 31 ++++++++++-- src/loader/index.ts | 50 +++++++++++++++---- 16 files changed, 109 insertions(+), 71 deletions(-) diff --git a/package-lock.json b/package-lock.json index 682e82a..079e9e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3312,6 +3312,14 @@ } } }, + "concat-with-sourcemaps": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/concat-with-sourcemaps/-/concat-with-sourcemaps-1.1.0.tgz", + "integrity": "sha512-4gEjHJFT9e+2W/77h/DS5SGUgwDaOwprX8L/gl5+3ixnzkVJJsZWDSelmN3Oilw3LNDZjZV0yqH1hLG3k6nghg==", + "requires": { + "source-map": "^0.6.1" + } + }, "console-browserify": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/console-browserify/-/console-browserify-1.2.0.tgz", @@ -10535,8 +10543,7 @@ "source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" }, "source-map-resolve": { "version": "0.5.3", diff --git a/package.json b/package.json index e2bcaeb..5d4f6be 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "bugs": "https://github.com/marko-js/webpack/issues", "dependencies": { "base-x": "^3.0.7", + "concat-with-sourcemaps": "^1.1.0", "lasso-modules-client": "^2.0.5", "loader-utils": "^1.4.0", "sort-keys": "^4.0.0", @@ -53,7 +54,7 @@ ], "license": "MIT", "peerDependencies": { - "marko": "^4.18.47", + "marko": "^4.18.47 || ^5", "webpack": "^4" }, "repository": { diff --git a/src/__tests__/fixtures/basic-template-plugin/__snapshots__/server--main.js b/src/__tests__/fixtures/basic-template-plugin/__snapshots__/server--main.js index 9a661cd..e11c0f0 100644 --- a/src/__tests__/fixtures/basic-template-plugin/__snapshots__/server--main.js +++ b/src/__tests__/fixtures/basic-template-plugin/__snapshots__/server--main.js @@ -43,8 +43,7 @@ http /***/ (function(module, exports, __webpack_require__) { "use strict"; -/* WEBPACK VAR INJECTION */(function(__filename) {// Compiled using marko@4.18.47 - DO NOT EDIT - +/* WEBPACK VAR INJECTION */(function(__filename) { var marko_template = module.exports = __webpack_require__(/*! marko/dist/html */ "marko/dist/html").t(__filename), marko_componentType = "/@marko/webpack-tests$x.x.x/fixtures/basic-template-plugin/test.marko", @@ -77,16 +76,14 @@ marko_template.meta = { /***/ (function(module, exports, __webpack_require__) { "use strict"; -/* WEBPACK VAR INJECTION */(function(__filename) {// Compiled using marko@4.18.47 - DO NOT EDIT - +/* WEBPACK VAR INJECTION */(function(__filename) { var marko_template = module.exports = __webpack_require__(/*! marko/dist/html */ "marko/dist/html").t(__filename), marko_componentType = "/@marko/webpack-tests$x.x.x/fixtures/basic-template-plugin/test.marko", marko_renderer = __webpack_require__(/*! marko/dist/runtime/components/renderer */ "marko/dist/runtime/components/renderer"), template = __webpack_require__(/*! ./test.marko */ "./src/__tests__/fixtures/basic-template-plugin/test.marko"), - module_MARKOWEBPACKMANIFEST_module = __webpack_require__(/*! ./../../../../__MARKO_WEBPACK__MANIFEST.js */ "./__MARKO_WEBPACK__MANIFEST.js"), - MARKOWEBPACKMANIFEST_module = module_MARKOWEBPACKMANIFEST_module.default || module_MARKOWEBPACKMANIFEST_module, - getAssets = module_MARKOWEBPACKMANIFEST_module.getAssets, + module_manifest = __webpack_require__(/*! ./../../../../__MARKO_WEBPACK__MANIFEST.js */ "./__MARKO_WEBPACK__MANIFEST.js"), + manifest = module_manifest.default || module_manifest, marko_dynamicTag = __webpack_require__(/*! marko/dist/runtime/helpers/dynamic-tag */ "marko/dist/runtime/helpers/dynamic-tag"), marko_loadTag = __webpack_require__(/*! marko/dist/runtime/helpers/load-tag */ "marko/dist/runtime/helpers/load-tag"), init_components_tag = marko_loadTag(__webpack_require__(/*! marko/dist/core-tags/components/init-components-tag */ "marko/dist/core-tags/components/init-components-tag")); @@ -139,7 +136,7 @@ function render(input, out, __component, component, state) { out.___renderAssets = renderAssets; - out.___assets = getAssets("test_uYWJ", out.global.buildName); + out.___assets = manifest.getAssets("test_uYWJ", out.global.buildName); out.flush = outFlushOverride; diff --git a/src/__tests__/fixtures/basic-template/__snapshots__/main.js b/src/__tests__/fixtures/basic-template/__snapshots__/main.js index 2206929..ceedafc 100644 --- a/src/__tests__/fixtures/basic-template/__snapshots__/main.js +++ b/src/__tests__/fixtures/basic-template/__snapshots__/main.js @@ -8,7 +8,6 @@ /***/ (function(module, exports, __webpack_require__) { "use strict"; -// Compiled using marko@4.18.47 - DO NOT EDIT var marko_template = module.exports = __webpack_require__(/*! marko/dist/vdom */ "marko/dist/vdom").t(), diff --git a/src/__tests__/fixtures/multiple-entries-plugin/__snapshots__/server--main.js b/src/__tests__/fixtures/multiple-entries-plugin/__snapshots__/server--main.js index e6a5fe8..ae3275e 100644 --- a/src/__tests__/fixtures/multiple-entries-plugin/__snapshots__/server--main.js +++ b/src/__tests__/fixtures/multiple-entries-plugin/__snapshots__/server--main.js @@ -24,8 +24,7 @@ module.exports = { /***/ (function(module, exports, __webpack_require__) { "use strict"; -/* WEBPACK VAR INJECTION */(function(__filename) {// Compiled using marko@4.18.47 - DO NOT EDIT - +/* WEBPACK VAR INJECTION */(function(__filename) { var marko_template = module.exports = __webpack_require__(/*! marko/dist/html */ "marko/dist/html").t(__filename), marko_componentType = "/@marko/webpack-tests$x.x.x/fixtures/multiple-entries-plugin/bar.marko", @@ -66,16 +65,14 @@ marko_template.meta = { /***/ (function(module, exports, __webpack_require__) { "use strict"; -/* WEBPACK VAR INJECTION */(function(__filename) {// Compiled using marko@4.18.47 - DO NOT EDIT - +/* WEBPACK VAR INJECTION */(function(__filename) { var marko_template = module.exports = __webpack_require__(/*! marko/dist/html */ "marko/dist/html").t(__filename), marko_componentType = "/@marko/webpack-tests$x.x.x/fixtures/multiple-entries-plugin/bar.marko", marko_renderer = __webpack_require__(/*! marko/dist/runtime/components/renderer */ "marko/dist/runtime/components/renderer"), template = __webpack_require__(/*! ./bar.marko */ "./src/__tests__/fixtures/multiple-entries-plugin/bar.marko"), - module_MARKOWEBPACKMANIFEST_module = __webpack_require__(/*! ./../../../../__MARKO_WEBPACK__MANIFEST.js */ "./__MARKO_WEBPACK__MANIFEST.js"), - MARKOWEBPACKMANIFEST_module = module_MARKOWEBPACKMANIFEST_module.default || module_MARKOWEBPACKMANIFEST_module, - getAssets = module_MARKOWEBPACKMANIFEST_module.getAssets, + module_manifest = __webpack_require__(/*! ./../../../../__MARKO_WEBPACK__MANIFEST.js */ "./__MARKO_WEBPACK__MANIFEST.js"), + manifest = module_manifest.default || module_manifest, marko_dynamicTag = __webpack_require__(/*! marko/dist/runtime/helpers/dynamic-tag */ "marko/dist/runtime/helpers/dynamic-tag"), marko_loadTag = __webpack_require__(/*! marko/dist/runtime/helpers/load-tag */ "marko/dist/runtime/helpers/load-tag"), init_components_tag = marko_loadTag(__webpack_require__(/*! marko/dist/core-tags/components/init-components-tag */ "marko/dist/core-tags/components/init-components-tag")); @@ -128,7 +125,7 @@ function render(input, out, __component, component, state) { out.___renderAssets = renderAssets; - out.___assets = getAssets("bar_aSxt", out.global.buildName); + out.___assets = manifest.getAssets("bar_aSxt", out.global.buildName); out.flush = outFlushOverride; @@ -166,8 +163,7 @@ marko_template.meta = { /***/ (function(module, exports, __webpack_require__) { "use strict"; -/* WEBPACK VAR INJECTION */(function(__filename) {// Compiled using marko@4.18.47 - DO NOT EDIT - +/* WEBPACK VAR INJECTION */(function(__filename) { var marko_template = module.exports = __webpack_require__(/*! marko/dist/html */ "marko/dist/html").t(__filename), marko_componentType = "/@marko/webpack-tests$x.x.x/fixtures/multiple-entries-plugin/components/shared.marko", @@ -200,8 +196,7 @@ marko_template.meta = { /***/ (function(module, exports, __webpack_require__) { "use strict"; -/* WEBPACK VAR INJECTION */(function(__filename) {// Compiled using marko@4.18.47 - DO NOT EDIT - +/* WEBPACK VAR INJECTION */(function(__filename) { var marko_template = module.exports = __webpack_require__(/*! marko/dist/html */ "marko/dist/html").t(__filename), marko_componentType = "/@marko/webpack-tests$x.x.x/fixtures/multiple-entries-plugin/foo.marko", @@ -242,16 +237,14 @@ marko_template.meta = { /***/ (function(module, exports, __webpack_require__) { "use strict"; -/* WEBPACK VAR INJECTION */(function(__filename) {// Compiled using marko@4.18.47 - DO NOT EDIT - +/* WEBPACK VAR INJECTION */(function(__filename) { var marko_template = module.exports = __webpack_require__(/*! marko/dist/html */ "marko/dist/html").t(__filename), marko_componentType = "/@marko/webpack-tests$x.x.x/fixtures/multiple-entries-plugin/foo.marko", marko_renderer = __webpack_require__(/*! marko/dist/runtime/components/renderer */ "marko/dist/runtime/components/renderer"), template = __webpack_require__(/*! ./foo.marko */ "./src/__tests__/fixtures/multiple-entries-plugin/foo.marko"), - module_MARKOWEBPACKMANIFEST_module = __webpack_require__(/*! ./../../../../__MARKO_WEBPACK__MANIFEST.js */ "./__MARKO_WEBPACK__MANIFEST.js"), - MARKOWEBPACKMANIFEST_module = module_MARKOWEBPACKMANIFEST_module.default || module_MARKOWEBPACKMANIFEST_module, - getAssets = module_MARKOWEBPACKMANIFEST_module.getAssets, + module_manifest = __webpack_require__(/*! ./../../../../__MARKO_WEBPACK__MANIFEST.js */ "./__MARKO_WEBPACK__MANIFEST.js"), + manifest = module_manifest.default || module_manifest, marko_dynamicTag = __webpack_require__(/*! marko/dist/runtime/helpers/dynamic-tag */ "marko/dist/runtime/helpers/dynamic-tag"), marko_loadTag = __webpack_require__(/*! marko/dist/runtime/helpers/load-tag */ "marko/dist/runtime/helpers/load-tag"), init_components_tag = marko_loadTag(__webpack_require__(/*! marko/dist/core-tags/components/init-components-tag */ "marko/dist/core-tags/components/init-components-tag")); @@ -304,7 +297,7 @@ function render(input, out, __component, component, state) { out.___renderAssets = renderAssets; - out.___assets = getAssets("foo_3XPO", out.global.buildName); + out.___assets = manifest.getAssets("foo_3XPO", out.global.buildName); out.flush = outFlushOverride; diff --git a/src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/__snapshots__/browser-A--test_YDNP.A.js b/src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/__snapshots__/browser-A--test_YDNP.A.js index 4f47937..ba8594f 100644 --- a/src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/__snapshots__/browser-A--test_YDNP.A.js +++ b/src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/__snapshots__/browser-A--test_YDNP.A.js @@ -8,7 +8,6 @@ /***/ (function(module, exports, __webpack_require__) { __webpack_require__(/*! ./style.css */ "./src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/components/nested/style.css"); -// Compiled using marko@4.18.47 - DO NOT EDIT "use strict"; var marko_template = module.exports = __webpack_require__(/*! marko/dist/vdom */ "marko/dist/vdom").t(), diff --git a/src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/__snapshots__/browser-B--test_YDNP.B.js b/src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/__snapshots__/browser-B--test_YDNP.B.js index b47a31b..8f8d41d 100644 --- a/src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/__snapshots__/browser-B--test_YDNP.B.js +++ b/src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/__snapshots__/browser-B--test_YDNP.B.js @@ -8,7 +8,6 @@ /***/ (function(module, exports, __webpack_require__) { __webpack_require__(/*! ./style.css */ "./src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/components/nested/style.css"); -// Compiled using marko@4.18.47 - DO NOT EDIT "use strict"; var marko_template = module.exports = __webpack_require__(/*! marko/dist/vdom */ "marko/dist/vdom").t(), diff --git a/src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/__snapshots__/browser-C--test_YDNP.C.js b/src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/__snapshots__/browser-C--test_YDNP.C.js index f911117..b17f612 100644 --- a/src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/__snapshots__/browser-C--test_YDNP.C.js +++ b/src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/__snapshots__/browser-C--test_YDNP.C.js @@ -8,7 +8,6 @@ /***/ (function(module, exports, __webpack_require__) { __webpack_require__(/*! ./style.css */ "./src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/components/nested/style.css"); -// Compiled using marko@4.18.47 - DO NOT EDIT "use strict"; var marko_template = module.exports = __webpack_require__(/*! marko/dist/vdom */ "marko/dist/vdom").t(), diff --git a/src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/__snapshots__/server--main.js b/src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/__snapshots__/server--main.js index 6085dff..44c0f90 100644 --- a/src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/__snapshots__/server--main.js +++ b/src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/__snapshots__/server--main.js @@ -29,8 +29,7 @@ module.exports = { /***/ (function(module, exports, __webpack_require__) { "use strict"; -/* WEBPACK VAR INJECTION */(function(__filename) {// Compiled using marko@4.18.47 - DO NOT EDIT - +/* WEBPACK VAR INJECTION */(function(__filename) { var marko_template = module.exports = __webpack_require__(/*! marko/dist/html */ "marko/dist/html").t(__filename), marko_component = { @@ -90,8 +89,7 @@ http /***/ (function(module, exports, __webpack_require__) { "use strict"; -/* WEBPACK VAR INJECTION */(function(__filename) {// Compiled using marko@4.18.47 - DO NOT EDIT - +/* WEBPACK VAR INJECTION */(function(__filename) { var marko_template = module.exports = __webpack_require__(/*! marko/dist/html */ "marko/dist/html").t(__filename), marko_componentType = "/@marko/webpack-tests$x.x.x/fixtures/with-class-component-plugin-dynamic-bundle/test.marko", @@ -140,16 +138,14 @@ marko_template.meta = { /***/ (function(module, exports, __webpack_require__) { "use strict"; -/* WEBPACK VAR INJECTION */(function(__filename) {// Compiled using marko@4.18.47 - DO NOT EDIT - +/* WEBPACK VAR INJECTION */(function(__filename) { var marko_template = module.exports = __webpack_require__(/*! marko/dist/html */ "marko/dist/html").t(__filename), marko_componentType = "/@marko/webpack-tests$x.x.x/fixtures/with-class-component-plugin-dynamic-bundle/test.marko", marko_renderer = __webpack_require__(/*! marko/dist/runtime/components/renderer */ "marko/dist/runtime/components/renderer"), template = __webpack_require__(/*! ./test.marko */ "./src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/test.marko"), - module_MARKOWEBPACKMANIFEST_module = __webpack_require__(/*! ./../../../../__MARKO_WEBPACK__MANIFEST.js */ "./__MARKO_WEBPACK__MANIFEST.js"), - MARKOWEBPACKMANIFEST_module = module_MARKOWEBPACKMANIFEST_module.default || module_MARKOWEBPACKMANIFEST_module, - getAssets = module_MARKOWEBPACKMANIFEST_module.getAssets, + module_manifest = __webpack_require__(/*! ./../../../../__MARKO_WEBPACK__MANIFEST.js */ "./__MARKO_WEBPACK__MANIFEST.js"), + manifest = module_manifest.default || module_manifest, marko_dynamicTag = __webpack_require__(/*! marko/dist/runtime/helpers/dynamic-tag */ "marko/dist/runtime/helpers/dynamic-tag"), marko_loadTag = __webpack_require__(/*! marko/dist/runtime/helpers/load-tag */ "marko/dist/runtime/helpers/load-tag"), init_components_tag = marko_loadTag(__webpack_require__(/*! marko/dist/core-tags/components/init-components-tag */ "marko/dist/core-tags/components/init-components-tag")); @@ -202,7 +198,7 @@ function render(input, out, __component, component, state) { out.___renderAssets = renderAssets; - out.___assets = getAssets("test_YDNP", out.global.buildName); + out.___assets = manifest.getAssets("test_YDNP", out.global.buildName); out.flush = outFlushOverride; diff --git a/src/__tests__/fixtures/with-class-component-plugin/__snapshots__/browser--test_nzzJ.js b/src/__tests__/fixtures/with-class-component-plugin/__snapshots__/browser--test_nzzJ.js index 9bab9be..e31bbee 100644 --- a/src/__tests__/fixtures/with-class-component-plugin/__snapshots__/browser--test_nzzJ.js +++ b/src/__tests__/fixtures/with-class-component-plugin/__snapshots__/browser--test_nzzJ.js @@ -8,7 +8,6 @@ /***/ (function(module, exports, __webpack_require__) { __webpack_require__(/*! ./style.css */ "./src/__tests__/fixtures/with-class-component-plugin/components/nested/style.css"); -// Compiled using marko@4.18.47 - DO NOT EDIT "use strict"; var marko_template = module.exports = __webpack_require__(/*! marko/dist/vdom */ "marko/dist/vdom").t(), diff --git a/src/__tests__/fixtures/with-class-component-plugin/__snapshots__/server--main.js b/src/__tests__/fixtures/with-class-component-plugin/__snapshots__/server--main.js index 8585152..14c3d1d 100644 --- a/src/__tests__/fixtures/with-class-component-plugin/__snapshots__/server--main.js +++ b/src/__tests__/fixtures/with-class-component-plugin/__snapshots__/server--main.js @@ -24,8 +24,7 @@ module.exports = { /***/ (function(module, exports, __webpack_require__) { "use strict"; -/* WEBPACK VAR INJECTION */(function(__filename) {// Compiled using marko@4.18.47 - DO NOT EDIT - +/* WEBPACK VAR INJECTION */(function(__filename) { var marko_template = module.exports = __webpack_require__(/*! marko/dist/html */ "marko/dist/html").t(__filename), marko_component = { @@ -83,8 +82,7 @@ http /***/ (function(module, exports, __webpack_require__) { "use strict"; -/* WEBPACK VAR INJECTION */(function(__filename) {// Compiled using marko@4.18.47 - DO NOT EDIT - +/* WEBPACK VAR INJECTION */(function(__filename) { var marko_template = module.exports = __webpack_require__(/*! marko/dist/html */ "marko/dist/html").t(__filename), marko_componentType = "/@marko/webpack-tests$x.x.x/fixtures/with-class-component-plugin/test.marko", @@ -133,16 +131,14 @@ marko_template.meta = { /***/ (function(module, exports, __webpack_require__) { "use strict"; -/* WEBPACK VAR INJECTION */(function(__filename) {// Compiled using marko@4.18.47 - DO NOT EDIT - +/* WEBPACK VAR INJECTION */(function(__filename) { var marko_template = module.exports = __webpack_require__(/*! marko/dist/html */ "marko/dist/html").t(__filename), marko_componentType = "/@marko/webpack-tests$x.x.x/fixtures/with-class-component-plugin/test.marko", marko_renderer = __webpack_require__(/*! marko/dist/runtime/components/renderer */ "marko/dist/runtime/components/renderer"), template = __webpack_require__(/*! ./test.marko */ "./src/__tests__/fixtures/with-class-component-plugin/test.marko"), - module_MARKOWEBPACKMANIFEST_module = __webpack_require__(/*! ./../../../../__MARKO_WEBPACK__MANIFEST.js */ "./__MARKO_WEBPACK__MANIFEST.js"), - MARKOWEBPACKMANIFEST_module = module_MARKOWEBPACKMANIFEST_module.default || module_MARKOWEBPACKMANIFEST_module, - getAssets = module_MARKOWEBPACKMANIFEST_module.getAssets, + module_manifest = __webpack_require__(/*! ./../../../../__MARKO_WEBPACK__MANIFEST.js */ "./__MARKO_WEBPACK__MANIFEST.js"), + manifest = module_manifest.default || module_manifest, marko_dynamicTag = __webpack_require__(/*! marko/dist/runtime/helpers/dynamic-tag */ "marko/dist/runtime/helpers/dynamic-tag"), marko_loadTag = __webpack_require__(/*! marko/dist/runtime/helpers/load-tag */ "marko/dist/runtime/helpers/load-tag"), init_components_tag = marko_loadTag(__webpack_require__(/*! marko/dist/core-tags/components/init-components-tag */ "marko/dist/core-tags/components/init-components-tag")); @@ -195,7 +191,7 @@ function render(input, out, __component, component, state) { out.___renderAssets = renderAssets; - out.___assets = getAssets("test_nzzJ", out.global.buildName); + out.___assets = manifest.getAssets("test_nzzJ", out.global.buildName); out.flush = outFlushOverride; diff --git a/src/__tests__/fixtures/with-css-extract/__snapshots__/main.js b/src/__tests__/fixtures/with-css-extract/__snapshots__/main.js index 528ae4f..03fb91b 100644 --- a/src/__tests__/fixtures/with-css-extract/__snapshots__/main.js +++ b/src/__tests__/fixtures/with-css-extract/__snapshots__/main.js @@ -8,7 +8,6 @@ /***/ (function(module, exports, __webpack_require__) { __webpack_require__(/*! ./test.marko.css */ "./src/__tests__/fixtures/with-css-extract/test.marko.css") -// Compiled using marko@4.18.47 - DO NOT EDIT "use strict"; var marko_template = module.exports = __webpack_require__(/*! marko/dist/vdom */ "marko/dist/vdom").t(), diff --git a/src/__tests__/fixtures/with-css/__snapshots__/main.js b/src/__tests__/fixtures/with-css/__snapshots__/main.js index 7802489..f675a6a 100644 --- a/src/__tests__/fixtures/with-css/__snapshots__/main.js +++ b/src/__tests__/fixtures/with-css/__snapshots__/main.js @@ -411,7 +411,6 @@ module.exports = function (list, options) { /***/ (function(module, exports, __webpack_require__) { __webpack_require__(/*! ./test.marko.css */ "./src/__tests__/fixtures/with-css/test.marko.css") -// Compiled using marko@4.18.47 - DO NOT EDIT "use strict"; var marko_template = module.exports = __webpack_require__(/*! marko/dist/vdom */ "marko/dist/vdom").t(), diff --git a/src/loader/get-asset-code.ts b/src/loader/get-asset-code.ts index a52d154..a00562d 100644 --- a/src/loader/get-asset-code.ts +++ b/src/loader/get-asset-code.ts @@ -4,7 +4,7 @@ import { VIRTUAL_SERVER_MANIFEST_PATH } from "../shared/virtual"; export default (resourcePath: string): string => ` import template from ${JSON.stringify(`./${path.basename(resourcePath)}`)}; -import { getAssets } from ${JSON.stringify( +import manifest from ${JSON.stringify( `./${path.relative(path.dirname(resourcePath), VIRTUAL_SERVER_MANIFEST_PATH)}` )}; @@ -50,7 +50,7 @@ static function outEndOverride(data, encoding, callback) { $ out.___flush = out.flush; $ out.___end = out.end; $ out.___renderAssets = renderAssets; -$ out.___assets = getAssets(${JSON.stringify( +$ out.___assets = manifest.getAssets(${JSON.stringify( moduleName(resourcePath) )}, out.global.buildName); $ out.flush = outFlushOverride; diff --git a/src/loader/head-transformer.ts b/src/loader/head-transformer.ts index e43dbc5..ab81f65 100644 --- a/src/loader/head-transformer.ts +++ b/src/loader/head-transformer.ts @@ -1,8 +1,33 @@ -export = function transformer(el, ctx): void { - const { builder } = ctx; +export = function transformer(a, b) { + if (a.hub) { + return transformerMarko5(a, b); + } + + return transformerMarko4(a, b); +}; + +function transformerMarko4(el, { builder }): void { el.appendChild( builder.scriptlet({ value: "out.___renderAssets && out.___renderAssets()" }) ); -}; +} + +function transformerMarko5(path, t): void { + const renderAssetsMember = t.memberExpression( + t.identifier("out"), + t.identifier("___renderAssets") + ); + path.replaceWith( + t.markoScriptlet([ + t.expressionStatement( + t.logicalExpression( + "&&", + renderAssetsMember, + t.callExpression(renderAssetsMember, []) + ) + ) + ]) + ); +} diff --git a/src/loader/index.ts b/src/loader/index.ts index ac4df4a..0c87135 100644 --- a/src/loader/index.ts +++ b/src/loader/index.ts @@ -2,6 +2,7 @@ import * as path from "path"; import * as loaderUtils from "loader-utils"; +import ConcatMap from "concat-with-sourcemaps"; import getAssetCode from "./get-asset-code"; import { getVirtualModules } from "../shared/virtual"; @@ -69,6 +70,14 @@ export default function(source: string): string { const dependenciesOnly = this.resource.endsWith("?dependencies"); const hydrate = this.resource.endsWith("?hydrate"); const assets = this.resource.endsWith("?assets"); + let sourceMaps = + !queryOptions || queryOptions.sourceMaps === undefined + ? this.sourceMap + : queryOptions.sourceMaps; + + if (sourceMaps === "inline") { + sourceMaps = true; + } this.cacheable(false); if (!cacheClearSetup.has(this._compiler)) { @@ -84,7 +93,8 @@ export default function(source: string): string { this.resourcePath, { writeToDisk: false, - requireTemplates: true + requireTemplates: true, + writeVersionComment: false } ); } else if (hydrate) { @@ -99,11 +109,14 @@ export default function(source: string): string { window.$initComponents && window.$initComponents(); `; } else if (target !== "server" && markoCompiler.compileForBrowser) { - const { code, meta } = markoCompiler.compileForBrowser( + const { code, meta, map } = markoCompiler.compileForBrowser( source, this.resourcePath, { - writeToDisk: false + sourceOnly: false, + writeToDisk: false, + writeVersionComment: false, + sourceMaps } ); @@ -161,22 +174,39 @@ export default function(source: string): string { } if (!dependenciesOnly) { - dependencies = dependencies.concat(code); + if (map) { + if (dependencies.length) { + const concat = new ConcatMap(true, "", ";"); + concat.add(null, dependencies.join("\n")); + concat.add(this.resource, code, map); + return this.callback(null, concat.content, concat.sourceMap); + } else { + this.callback(null, code, map); + } + } else { + dependencies.push(code); + } } return dependencies.join("\n"); } else { - const { code, meta } = markoCompiler.compile(source, this.resourcePath, { - sourceOnly: false, - writeToDisk: false, - requireTemplates: true - }); + const { code, meta, map } = markoCompiler.compile( + source, + this.resourcePath, + { + sourceOnly: false, + writeToDisk: false, + requireTemplates: true, + writeVersionComment: false, + sourceMaps + } + ); getMissingWatchDeps(this.resourcePath, meta).forEach(dep => this.addDependency(dep) ); - return code; + return this.callback(null, code, map); } }