2

I have several npm packages with client-side scripts I want to include to separate pages of my Nuxt.js project. I have tried to do that with:

<script>
export default {
  head: {
    script: [
      { src: "gojs/release/go.js", type: "text/javascript" }
    ]
  },

  // ...
}
</script> 

but received 404 (Not Found) error. What is correct way to do that?

4
  • Try including the files as static assets (e.g., /assets/static/gojs/release/go.js), which will make them available at the root (/). Then in your .vue, the src url should be prefixed with / (/gojs/release/go.js). Commented Mar 4, 2019 at 19:17
  • Yes, I know about this way, but I want to include scripts from node_modules so when I update packages with npm - they will be updated. Commented Mar 6, 2019 at 16:20
  • importing them in plugin with ssr false dont fit? Commented Mar 6, 2019 at 21:33
  • 1
    Oh, I misunderstood. Normally, importing the module (e.g., with import go from 'gojs') and using it in your code are all you need to do for the build to include that dependency. See this demo Commented Mar 7, 2019 at 1:47

1 Answer 1

1

Normally, import-ing the module (e.g., with import go from 'gojs') and using it in your code are all you need to do for the build to include that dependency. No need to add headers to load the NPM module.

Example in MyFoo.vue:

<script>
import go from 'gojs'

export default {
  mounted() {
    const $ = go.GraphObject.make;
    const myDiagram =
      $(go.Diagram, "myDiagramDiv",
        {
          "undoManager.isEnabled": true
        });

    ...
  }
}
</script>

demo

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.