├── .gitignore ├── LICENSE ├── README.md ├── assets └── js │ ├── lib │ └── index.js │ ├── like.jsx │ ├── main.js │ ├── myworker.js │ └── shims │ ├── process.js │ ├── react-dom.js │ └── react.js ├── config.toml ├── go.mod ├── go.sum ├── layouts └── index.html ├── netlify.toml ├── package-lock.json ├── package.hugo.json └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | public/ 2 | assets/jsconfig.json 3 | !node_modules/ 4 | node_modules/* 5 | !node_modules/mynodemod/ 6 | resources/ 7 | .vscode/ 8 | .hugo_build.lock -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 GoHugo.io 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # hugoTestProjectJSModImports 2 | Test project used for integration testing. 3 | 4 | Netlify deploy: https://nifty-curran-a09698.netlify.app/ 5 | -------------------------------------------------------------------------------- /assets/js/lib/index.js: -------------------------------------------------------------------------------- 1 | export function hello4() { 2 | return 'Hello from lib in the main project!!'; 3 | } 4 | -------------------------------------------------------------------------------- /assets/js/like.jsx: -------------------------------------------------------------------------------- 1 | // Note: We're using the CDN in "production". 2 | import * as React from 'react'; 3 | import * as ReactDOM from 'react-dom/client'; 4 | 5 | // A simple React JSX component. 6 | class LikeButton extends React.Component { 7 | constructor(props) { 8 | super(props); 9 | this.state = { liked: false }; 10 | } 11 | 12 | render() { 13 | if (this.state.liked) { 14 | return 'You liked this!'; 15 | } 16 | 17 | return ( 18 | 21 | ); 22 | } 23 | } 24 | 25 | 26 | 27 | 28 | const root = ReactDOM.createRoot(document.querySelector('#like_button_container')); 29 | root.render(); -------------------------------------------------------------------------------- /assets/js/main.js: -------------------------------------------------------------------------------- 1 | //// From mod1, but hello1 get its data from mod2. 2 | import { hello1, hello2 } from 'core/util'; 3 | // From mod2 4 | import * as data from 'core/util/data.json'; 5 | // hello3, hello6 lives in mod2 which also have a index.js in util. 6 | // But doing import from 'core/util' you will get the index.js file from mod1 7 | // (higher up in the import list), so we need to be explicit: 8 | import { hello3, hello6 } from 'core/util/hello3'; 9 | 10 | // From main 11 | import { hello4 } from './lib'; 12 | // From the Hugo template. 13 | import * as params from '@params'; 14 | 15 | var worker = new Worker(params.myworker); 16 | 17 | worker.addEventListener( 18 | 'message', 19 | function(e) { 20 | console.log('Worker said: ', e.data); 21 | }, 22 | false 23 | ); 24 | 25 | worker.postMessage('Hello Worker'); 26 | 27 | // https://github.com/gohugoio/hugo/issues/7948 28 | // TODO(bep) make this work in Hugo integration tests import { helloNodeModules } from 'mynodemod'; 29 | 30 | window.hello1 = hello1; 31 | window.hello2 = hello2; 32 | window.hello3 = hello3; 33 | window.hello4 = hello4; 34 | window.hello6 = hello6; 35 | window.cwd = process.cwd; // Shim injected 36 | // TODO(bep) make this work in Hugo integration tests window.helloNodeModules = helloNodeModules; 37 | window.data = data; 38 | window.params = params; 39 | -------------------------------------------------------------------------------- /assets/js/myworker.js: -------------------------------------------------------------------------------- 1 | self.addEventListener( 2 | 'message', 3 | function(e) { 4 | self.postMessage('Echo From Worker: ' + e.data); 5 | }, 6 | false 7 | ); 8 | -------------------------------------------------------------------------------- /assets/js/shims/process.js: -------------------------------------------------------------------------------- 1 | export let process = { 2 | cwd: () => 'shim cwd' 3 | }; 4 | -------------------------------------------------------------------------------- /assets/js/shims/react-dom.js: -------------------------------------------------------------------------------- 1 | module.exports = window.ReactDOM; 2 | -------------------------------------------------------------------------------- /assets/js/shims/react.js: -------------------------------------------------------------------------------- 1 | module.exports = window.React; 2 | -------------------------------------------------------------------------------- /config.toml: -------------------------------------------------------------------------------- 1 | baseURL = "https://example.org" 2 | 3 | disableKinds = ["page", "section", "term", "taxonomy"] 4 | 5 | 6 | [module] 7 | [[module.imports]] 8 | path="github.com/gohugoio/hugoTestModulesJS/mod1" 9 | [[module.imports]] 10 | path="github.com/gohugoio/hugoTestModulesJS/mod2" 11 | [[module.imports]] 12 | path="github.com/date-fns/date-fns" 13 | [[module.imports.mounts]] 14 | source="src" 15 | target="assets/date" 16 | 17 | [[module.imports]] 18 | # This is not relevant for the testing itself. 19 | path = "github.com/bep/hugo-jslibs/alpinejs" -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/gohugoio/hugoTestProjectJSModImports 2 | 3 | go 1.15 4 | 5 | require ( 6 | github.com/bep/hugo-jslibs/alpinejs v0.5.14 // indirect 7 | github.com/date-fns/date-fns v2.16.1+incompatible // indirect 8 | github.com/gohugoio/hugoTestModulesJS/mod1 v0.2.0 // indirect 9 | github.com/gohugoio/hugoTestModulesJS/mod2 v0.3.0 // indirect 10 | ) 11 | 12 | 13 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/alpinejs/alpine v2.5.0+incompatible h1:dEOJPy27Kdno2wI51sr8ZkU+7QaLmLYLPD2sZfVe3Fw= 2 | github.com/alpinejs/alpine v2.5.0+incompatible/go.mod h1:BKI81egATMnaKqFeX5HEfYMnjZjcjcZmrYAu5Nck+EY= 3 | github.com/bep/hugo-jslibs v0.0.0-20200822141830-44620243312e h1:JWYiSAOCdD0HO7ySFZgwiQcq4/vqObqTqesFSJ2sesw= 4 | github.com/bep/hugo-jslibs/alpinejs v0.5.14 h1:PeZOraYYU+bH10G2Y/5M5VJsqOQyLAWCukvUIyQeTlE= 5 | github.com/bep/hugo-jslibs/alpinejs v0.5.14/go.mod h1:AKan86yhrI16Cp+ga/+UuRkBgaO25SpubHWFgMTzh3o= 6 | github.com/date-fns/date-fns v1.30.1 h1:zxR21/H1aFIN9dJnRPgWzm/d4vMjiPv0daTAJ+lJYJk= 7 | github.com/date-fns/date-fns v2.16.1+incompatible h1:MhC76uGURHPWnZhfKDJs+ckojxxKwAFd3D/7VN3NQKo= 8 | github.com/date-fns/date-fns v2.16.1+incompatible/go.mod h1:+ryiPUdf29FTxQJUxCwq0ip75zSWtk43q+htSAQLdFU= 9 | github.com/gohugoio/hugoTestModulesJS v0.0.0-20201010100233-8db744a82e35 h1:Cha7HDCdZ57kmJpY5GgHNPoW8R1aRCHm9vOTe4wmJOg= 10 | github.com/gohugoio/hugoTestModulesJS v0.0.0-20201011192008-decf54abafdd h1:IyL0HL6wUsRyCDelBh38gfDoiKMpJRrSJZDDdUVsiKo= 11 | github.com/gohugoio/hugoTestModulesJS/mod1 v0.0.0-20201010100233-8db744a82e35/go.mod h1:IfctxwCwBB4wVUA+bUb4o5x2mvphWPXVLhKaclkpwz4= 12 | github.com/gohugoio/hugoTestModulesJS/mod1 v0.0.0-20201010100603-5c7000b063e3 h1:6oAL5GX/uwfxpHog2bvTq2ARbf/strSuRZIX/KjZbIg= 13 | github.com/gohugoio/hugoTestModulesJS/mod1 v0.0.0-20201010100603-5c7000b063e3/go.mod h1:IfctxwCwBB4wVUA+bUb4o5x2mvphWPXVLhKaclkpwz4= 14 | github.com/gohugoio/hugoTestModulesJS/mod1 v0.0.0-20201011174806-5f7e20f9ff4a h1:h/+C4m4Aav50zgU2pfm2+GpuhoEgwVKkiRhDK2fjADs= 15 | github.com/gohugoio/hugoTestModulesJS/mod1 v0.0.0-20201011174806-5f7e20f9ff4a/go.mod h1:IfctxwCwBB4wVUA+bUb4o5x2mvphWPXVLhKaclkpwz4= 16 | github.com/gohugoio/hugoTestModulesJS/mod1 v0.1.0/go.mod h1:IfctxwCwBB4wVUA+bUb4o5x2mvphWPXVLhKaclkpwz4= 17 | github.com/gohugoio/hugoTestModulesJS/mod1 v0.2.0 h1:1eqMM/f0bOt3Y+8OCjFrCeNzS0ZQ3HpkMJrsth43Pvk= 18 | github.com/gohugoio/hugoTestModulesJS/mod1 v0.2.0/go.mod h1:IfctxwCwBB4wVUA+bUb4o5x2mvphWPXVLhKaclkpwz4= 19 | github.com/gohugoio/hugoTestModulesJS/mod2 v0.0.0-20201011192008-decf54abafdd h1:Uu3lXkigL0q13sVksE7NVnoPTyxx4ViYKrNA70QDKA4= 20 | github.com/gohugoio/hugoTestModulesJS/mod2 v0.0.0-20201011192008-decf54abafdd/go.mod h1:uynOkor8I03PIUuDZN4NYQ+Bmkye7vNLV5tRUBC2+10= 21 | github.com/gohugoio/hugoTestModulesJS/mod2 v0.1.0/go.mod h1:uynOkor8I03PIUuDZN4NYQ+Bmkye7vNLV5tRUBC2+10= 22 | github.com/gohugoio/hugoTestModulesJS/mod2 v0.2.0/go.mod h1:uynOkor8I03PIUuDZN4NYQ+Bmkye7vNLV5tRUBC2+10= 23 | github.com/gohugoio/hugoTestModulesJS/mod2 v0.3.0 h1:E9OmDOUcxxHxz1TaGEWv8WgNFi1UO31yBxjNbV2Jo0A= 24 | github.com/gohugoio/hugoTestModulesJS/mod2 v0.3.0/go.mod h1:uynOkor8I03PIUuDZN4NYQ+Bmkye7vNLV5tRUBC2+10= 25 | -------------------------------------------------------------------------------- /layouts/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | {{ .Title }} 7 | 8 | {{ if (not hugo.IsDevelopment) }} 9 | {{/* We import from node_modules in development to get code completion etc. working. */}} 10 | 13 | 16 | {{ end }} 17 | {{/* We (Hugo/ESBuild) needs to improve the worker integration, but this could be a OK workaround. */}} 18 | {{ $worker := resources.Get "js/myworker.js" | js.Build }} 19 | {{ $inject := slice "js/shims/process.js" }} 20 | {{ $js := resources.Get "js/main.js" | js.Build (dict "minify" false "params" (dict "myparam" "Hugo Rocks!" "myworker" $worker.RelPermalink) "inject" $inject ) }} 21 | 22 | {{ partialCached "jslibs/alpinejs/script-src.html" "-" }} 23 | 24 | 25 |

Basic Test Cases

26 |
27 | 38 |
39 |

React

40 |
41 | {{ $shims := dict }} 42 | {{ $defines := dict }} 43 | {{ if hugo.IsDevelopment }} 44 | {{ $defines = dict "process.env.NODE_ENV" `"development"` }} 45 | {{ else }} 46 | {{ $shims = dict "react" "js/shims/react.js" "react-dom/client" "js/shims/react-dom.js" }} 47 | {{ end }} 48 | {{ $js := resources.Get "js/like.jsx" | js.Build (dict "shims" $shims "defines" $defines ) }} 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | publish = "public" 3 | command = "hugo --gc --minify" 4 | 5 | [build.environment] 6 | HUGO_VERSION = "0.128.0" 7 | 8 | [context.deploy-preview] 9 | command = "hugo --gc --minify --buildFuture -b $DEPLOY_PRIME_URL" 10 | 11 | [context.branch-deploy] 12 | command = "hugo --gc --minify -b $DEPLOY_PRIME_URL" 13 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hugotestprojectjsmodimports", 3 | "version": "1.0.0", 4 | "lockfileVersion": 2, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "hugotestprojectjsmodimports", 9 | "version": "1.0.0", 10 | "license": "ISC", 11 | "dependencies": { 12 | "date-fns": "^2.16.1" 13 | }, 14 | "devDependencies": { 15 | "react": "^18.3.1", 16 | "react-dom": "^18.3.1" 17 | } 18 | }, 19 | "node_modules/date-fns": { 20 | "version": "2.16.1", 21 | "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.16.1.tgz", 22 | "integrity": "sha512-sAJVKx/FqrLYHAQeN7VpJrPhagZc9R4ImZIWYRFZaaohR3KzmuK88touwsSwSVT8Qcbd4zoDsnGfX4GFB4imyQ==", 23 | "engines": { 24 | "node": ">=0.11" 25 | }, 26 | "funding": { 27 | "type": "opencollective", 28 | "url": "https://opencollective.com/date-fns" 29 | } 30 | }, 31 | "node_modules/js-tokens": { 32 | "version": "4.0.0", 33 | "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", 34 | "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", 35 | "dev": true 36 | }, 37 | "node_modules/loose-envify": { 38 | "version": "1.4.0", 39 | "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", 40 | "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", 41 | "dev": true, 42 | "dependencies": { 43 | "js-tokens": "^3.0.0 || ^4.0.0" 44 | }, 45 | "bin": { 46 | "loose-envify": "cli.js" 47 | } 48 | }, 49 | "node_modules/react": { 50 | "version": "18.3.1", 51 | "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", 52 | "integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==", 53 | "dev": true, 54 | "dependencies": { 55 | "loose-envify": "^1.1.0" 56 | }, 57 | "engines": { 58 | "node": ">=0.10.0" 59 | } 60 | }, 61 | "node_modules/react-dom": { 62 | "version": "18.3.1", 63 | "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz", 64 | "integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==", 65 | "dev": true, 66 | "dependencies": { 67 | "loose-envify": "^1.1.0", 68 | "scheduler": "^0.23.2" 69 | }, 70 | "peerDependencies": { 71 | "react": "^18.3.1" 72 | } 73 | }, 74 | "node_modules/scheduler": { 75 | "version": "0.23.2", 76 | "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz", 77 | "integrity": "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==", 78 | "dev": true, 79 | "dependencies": { 80 | "loose-envify": "^1.1.0" 81 | } 82 | } 83 | }, 84 | "dependencies": { 85 | "date-fns": { 86 | "version": "2.16.1", 87 | "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.16.1.tgz", 88 | "integrity": "sha512-sAJVKx/FqrLYHAQeN7VpJrPhagZc9R4ImZIWYRFZaaohR3KzmuK88touwsSwSVT8Qcbd4zoDsnGfX4GFB4imyQ==" 89 | }, 90 | "js-tokens": { 91 | "version": "4.0.0", 92 | "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", 93 | "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", 94 | "dev": true 95 | }, 96 | "loose-envify": { 97 | "version": "1.4.0", 98 | "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", 99 | "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", 100 | "dev": true, 101 | "requires": { 102 | "js-tokens": "^3.0.0 || ^4.0.0" 103 | } 104 | }, 105 | "react": { 106 | "version": "18.3.1", 107 | "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", 108 | "integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==", 109 | "dev": true, 110 | "requires": { 111 | "loose-envify": "^1.1.0" 112 | } 113 | }, 114 | "react-dom": { 115 | "version": "18.3.1", 116 | "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz", 117 | "integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==", 118 | "dev": true, 119 | "requires": { 120 | "loose-envify": "^1.1.0", 121 | "scheduler": "^0.23.2" 122 | } 123 | }, 124 | "scheduler": { 125 | "version": "0.23.2", 126 | "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz", 127 | "integrity": "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==", 128 | "dev": true, 129 | "requires": { 130 | "loose-envify": "^1.1.0" 131 | } 132 | } 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /package.hugo.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": "", 3 | "bugs": { 4 | "url": "https://github.com/gohugoio/hugoTestProjectJSModImports/issues" 5 | }, 6 | "comments": { 7 | "dependencies": { 8 | "date-fns": "github.com/gohugoio/hugoTestModulesJS/mod2" 9 | }, 10 | "devDependencies": { 11 | "react": "^17.0.1", 12 | "react-dom": "^17.0.1" 13 | } 14 | }, 15 | "dependencies": { 16 | "date-fns": "^2.16.1" 17 | }, 18 | "description": "Test project used for integration testing.", 19 | "devDependencies": { 20 | "react": "^17.0.1", 21 | "react-dom": "^17.0.1" 22 | }, 23 | "homepage": "https://github.com/gohugoio/hugoTestProjectJSModImports#readme", 24 | "license": "ISC", 25 | "main": "index.js", 26 | "name": "hugotestprojectjsmodimports", 27 | "repository": { 28 | "type": "git", 29 | "url": "git+https://github.com/gohugoio/hugoTestProjectJSModImports.git" 30 | }, 31 | "scripts": { 32 | "test": "echo \"Error: no test specified\" && exit 1" 33 | }, 34 | "version": "1.0.0" 35 | } 36 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": "", 3 | "bugs": { 4 | "url": "https://github.com/gohugoio/hugoTestProjectJSModImports/issues" 5 | }, 6 | "comments": { 7 | "dependencies": { 8 | "date-fns": "project" 9 | }, 10 | "devDependencies": { 11 | "react": "project", 12 | "react-dom": "project" 13 | } 14 | }, 15 | "dependencies": { 16 | "date-fns": "^2.16.1" 17 | }, 18 | "description": "Test project used for integration testing.", 19 | "devDependencies": { 20 | "react": "^18.3.1", 21 | "react-dom": "^18.3.1" 22 | }, 23 | "homepage": "https://github.com/gohugoio/hugoTestProjectJSModImports#readme", 24 | "license": "ISC", 25 | "main": "index.js", 26 | "name": "hugotestprojectjsmodimports", 27 | "repository": { 28 | "type": "git", 29 | "url": "git+https://github.com/gohugoio/hugoTestProjectJSModImports.git" 30 | }, 31 | "scripts": { 32 | "test": "echo \"Error: no test specified\" && exit 1" 33 | }, 34 | "version": "1.0.0" 35 | } 36 | --------------------------------------------------------------------------------