0

I'm trying to get pwa up, but it's giving an error "undefined" to the library inside my node modules file.

index.html page

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Vite + Vue</title>
    <script type="text/javascript">
      mxBasePath = './node_modules/mxgraph/javascript/src';
    </script>
    <script type="text/javascript" src="./node_modules/mxgraph/javascript/src/js/mxClient.js"></script>
  </head>
</html>

I am getting an error when loading this library.

 <script type="text/javascript" src="./node_modules/mxgraph/javascript/src/js/mxClient.js">

viteconfig.js page

export default defineConfig({
  plugins: [
    vue(),
    VitePWA({
      registerType: 'autoUpdate',
      injectRegister: 'auto',
      workbox: {
        cleanupOutdatedCaches: true,
        globPatterns: ['**/*.{js,css,html,ico,png,svg,json,vue,txt,woff2}']
      },
      manifest: {
        name: 'demo',
        short_name: 'demodemo',
        icons: [
          {
            src: '/pwa/img/48x48.png',
            sizes: '48x48',
            type: 'image/png'
          },
        ],
        theme_color: '#ffffff',
        background_color: '#1f1f1f',
        display: 'standalone',
        orientation: 'portrait'
      },
      devOptions: {
        enabled: true,
        type: 'module'
      }
    })
  ]
});

celal
  • 1
  • 1
  • Don't use scripts from src/ that are not yours without a good reason. – Estus Flask Mar 16 '23 at 19:34
  • @EstusFlask well How can I do? I mean How can I use that library in my project? I have developed that with library – celal Mar 16 '23 at 19:59
  • Import from dist/ , like with any third-party lib – Estus Flask Mar 16 '23 at 21:12
  • @EstusFlask Im sorry, Import from dist/, Where will I add them I dont know – celal Mar 16 '23 at 21:26
  • @EstusFlask to viteconfig.js file ? If rigth How can import viteconfig.js file – celal Mar 16 '23 at 21:27
  • Needs to be confirmed for this library, but basically https://stackoverflow.com/questions/68376035/how-to-include-css-from-node-modules-in-vite-in-production . Try to import `mxgraph/javascript/dist/build.js` or `mxgraph/javascript/mxClient.js` – Estus Flask Mar 16 '23 at 21:32

0 Answers0