0

I am creating a second BrowserWindow and loading an html file. HTML file points to a TypeScript file. Therefore, it's giving error. How do I tell parcel to transpile that file to js and load the url in the main process?

// main.ts
const windows: BrowserWindow[] = []

ipcMain.on('something:start', (event: Event) => {
  const url = format({
    pathname: resolve('app/renderer/secondWindow.html'),
    protocol: 'file:',
    slashes: true
  })

  const window = new BrowserWindow({ width: 800, height: 600, show: true })
  window.loadURL(url)
  window.on('closed', () => {
    windows.splice(windows.findIndex(w => w === window), 1)
  })

  windows.push(window)
})

//secondWindow.html
<html>
  <head>
    <meta charset="UTF-8" />
    <title>LetLock - Encrypt process</title>
  </head>
  <body>
    <div id="root"></div>
  </body>
  <script src="./someFunctions.ts"></script>
</html>


// package.json
  "scripts": {
    "start": "run-p -r parcel:launch electron:launch",
    "dist": "run-s parcel:build \"electron:build {@}\" --",
    "electron:launch": "run-s parcel:main electron:start",
    "electron:start": "electron .",
    "electron:build": "build --dir --x64 --publish=never",
    "parcel:launch": "parcel app/renderer/index.html --port 1124 --out-dir app/renderer/.parcel/development",
    "parcel:build": "run-s parcel:main parcel:renderer",
    "parcel:main": "parcel build app/main/main.ts --out-dir app/main/.parcel --out-file main --target electron",
    "parcel:renderer": "parcel build app/renderer/index.html --public-url ./ --out-dir app/renderer/.parcel/production",
    "test": "run-s parcel:build \"test:jest {@}\" --",
    "test:jest": "jest",
    "lint": "tslint app/**/*.ts{,x}"
  },
oyalhi
  • 3,834
  • 4
  • 40
  • 45
  • You should be able to import the (.html) file and the imported variabl should contain the relative url – Hans Koch Dec 13 '18 at 10:26
  • The html file is imported successfully and the html file has the script tag for the related .ts file; however, it's not transpiled by Parcel to js therefore I'm getting errors. How to make sure Parcel transpiles and points to the correct js file. – oyalhi Dec 13 '18 at 16:53

1 Answers1

0

I would expect the transpile to be done before you try to reference it and run time. Therefore reference the result of transpiling - i.e. the .js file?

double-beep
  • 5,031
  • 17
  • 33
  • 41
Martin Alley
  • 121
  • 1
  • 9