0

I am using vue2, my build tool is [email protected]. In order to debug the vue source component file easily, I add a configuration in output.devtoolModuleFilenameTemplate, the code is as below:

const resPath = path.normalize(info.resourcePath)
const isVue = resPath.match(/\.vue$/)
const isGenerated = info.allLoaders
const isTypeScript = info.allLoaders && info.allLoaders.includes('ts-loader')

const generated = `webpack-generated:///${resPath}?${info.hash}`
const vuesource = `vue-source:///${resPath}`

if (isVue) {
    if (!isGenerated || isTypeScript) {
        return vuesource
    } else {
        return generated
    }
} else {
    return vuesource
}

The devtool config is devtool: 'source-map'.

Now what's weird is, if the vue component is written in pure javascript, then I can find the source file easily, refer to below: source file

When click the above highlight part, show the content as below:

enter image description here

However, if the vue component is wrtten in typescript, which means has below declaration in vue component:

<script lang="ts">
  export default {
    ...
  }
</script>

When click the highlight part, it will show below content: enter image description here

The full content is as below:

import mod from "-!../../../node_modules/happypack/loader.js?id=happyTs!../../../node_modules/ts-loader/index.js??clonedRuleSet-4.use[1]!../../../node_modules/thread-loader/dist/cjs.js!../../../node_modules/vue-loader/lib/index.js??vue-loader-options!./ManageApprovalAction.vue?vue&type=script&lang=ts"; export default mod; export * from "-!../../../node_modules/happypack/loader.js?id=happyTs!../../../node_modules/ts-loader/index.js??clonedRuleSet-4.use[1]!../../../node_modules/thread-loader/dist/cjs.js!../../../node_modules/vue-loader/lib/index.js??vue-loader-options!./ManageApprovalAction.vue?vue&type=script&lang=ts"

Does anybody know why can not show the original source file content in this case ?

1 Answer 1

0

How are you? Plz ensure that your Webpack configuration accurately reflects the loader settings for both JavaScript and TypeScript files. You may need to configure vue-loader and ts-loader properly to handle .vue files containing TypeScript. you can ensure that the mappings are correct and that they point back to the correct *.vue files by using the browser's developer tools to inspect the generated source maps , By ensuring that your loaders are configured correctly, simplifying your logic, and possibly using additional source map loaders, you should be able to improve your debugging experience for Vue components, whether they are written in JavaScript or TypeScript. Make sure to test each change to observe how it affects your source maps in practice. Happy coding!

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.