简体   繁体   English

Webpack 和 vue-loader 与依赖项一起工作

[英]Webpack and vue-loader to work with a dependency

I have a privately built dependency that is compiled down to commonjs in my project.我有一个私有构建的依赖项,它在我的项目中编译为 commonjs。

Within the dependency itself, it references a file in my project, a vue file.在依赖项本身中,它引用了我项目中的一个文件,一个 vue 文件。 After building with webpack, and using ssr, it seems to have an issue.在使用 webpack 构建并使用 ssr 后,似乎有问题。 It fails to load the vue file.加载vue文件失败。

For clarity, folder structure:为清楚起见,文件夹结构:

node_modules
    |
    |- dependency
           |
           |-main.js
src
 |
 |-pages
     |
     |-Default.vue
dist
 |
 |-compiledcode.js <- what webpack compiles

Now in main.js of the dependency, I have const vuefile = require('../../src/pages/Default.vue')现在在依赖项的 main.js 中,我有const vuefile = require('../../src/pages/Default.vue')

The error as displayed by Node once hosting it via ssr:通过 ssr 托管 Node 后显示的错误:

<template>
^

SyntaxError: Unexpected token '<'

In my webpack i have the following:在我的 webpack 中,我有以下内容:

module.exports = {
  ...
  module: {    
       rules: [
          {
           test: /\.vue$/,
           loader: 'vue-loader',        
          },
          ...
       ]
   },
   plugins: [
      new VueLoaderPlugin()
      ...
   ]
}

From how I am understanding the error is that vue-loader isn't loading in the file.根据我的理解,错误是 vue-loader 没有加载到文件中。 But I don't even know this is possible to begin with.但我什至不知道这是否可能开始。 If there can be clarification on this.如果可以对此进行澄清。

If not possible..如果不可能..

Is it possible to then add a webconfig to the dependency and make it work that way?然后是否可以将 webconfig 添加到依赖项并使其以这种方式工作? If so, how do I get my webpack to interact with the dependencies webpack.如果是这样,我如何让我的 webpack 与依赖项 webpack 交互。

Thanks.谢谢。

can you please show your whole config?你能展示你的整个配置吗?

  1. set webpack resolve (incl extension resolve)设置webpack 解析(包括扩展解析)
  2. is vue included in main.js? vue 是否包含在 main.js 中? (import vue..) (导入vue..)
  3. setup alias to prevent paths like '../../src/pages/..'设置别名以防止像'../../src/pages/..'这样的路径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM