airyland / vux-loader

hack into vue-loader
64 stars 37 forks source link

[Feature Request] 是否支持新的vue/cli@3.0 #66

Closed wzc0x0 closed 5 years ago

wzc0x0 commented 6 years ago

Existing Component

Component Name

vux-loader

Description

新的vue/cli@3.0已经把webpack配置内置了,这样vux-loader没法merge配置了,配合vux使用就会打包报错

chengzhuotc commented 6 years ago

怎么解决这个问题呢

Jiiiiiin commented 6 years ago

vux-loader没法merge配置,这种说法就不对了,merge是肯定可以的,只是说目前针对vue-loader的适配没有做好。

xhhcocos2d commented 6 years ago

我已经把代码改的面目全废了,还是没啥用,坐等老大处理吧,webpack相关的真的是一点都不懂

llsy commented 6 years ago

有计划一个适配时间吗?

lvisei commented 6 years ago

我也遇到了这个问题 💌

co-kevin commented 6 years ago

这样改可以适应原有的 webpack 配置,但还有个问题是和 vue-loader@15.x.x 冲突,会出现下面的 Error,需要手动降级 vue-loader 方可使用

// vue.config.js
const vuxLoader = require('vux-loader')

module.exports = {
  configureWebpack: config => {
    vuxLoader.merge(config, {
      options: {},
      plugins: ['vux-ui']
    })
  }
}

Error Log

 ERROR  Failed to compile with 1 errors                                                                                                                                      14:39:47

 error  in ./src/views/Home.vue

Module parse failed: Unexpected token (3:0)
You may need an appropriate loader to handle this file type.
| import { render, staticRenderFns } from "./Home.vue?vue&type=template&id=fae5bece&"
| import script from "./Home.vue?vue&type=script&lang=js&"
> ../../node_modules/vux-loader/src/script-loader.js!export * from "./Home.vue?vue&type=script&lang=js&"
|
|

 @ ./src/router.js 3:0-36 11:15-19
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://localhost:8080/sockjs-node (webpack)/hot/dev-server.js ./src/main.js

降级

Yarn

$ yarn add -D vue-loader@14.2.3

Npm

$ npm i vue-loader@14.2.3 --save-dev
Fun005 commented 5 years ago

这样改可以适应原有的 webpack 配置,但还有个问题是和 vue-loader@15.x.x 冲突,会出现下面的 Error,需要手动降级 vue-loader 方可使用

// vue.config.js
const vuxLoader = require('vux-loader')

module.exports = {
  configureWebpack: config => {
    vuxLoader.merge(config, {
      options: {},
      plugins: ['vux-ui']
    })
  }
}

Error Log

 ERROR  Failed to compile with 1 errors                                                                                                                                      14:39:47

 error  in ./src/views/Home.vue

Module parse failed: Unexpected token (3:0)
You may need an appropriate loader to handle this file type.
| import { render, staticRenderFns } from "./Home.vue?vue&type=template&id=fae5bece&"
| import script from "./Home.vue?vue&type=script&lang=js&"
> ../../node_modules/vux-loader/src/script-loader.js!export * from "./Home.vue?vue&type=script&lang=js&"
|
|

 @ ./src/router.js 3:0-36 11:15-19
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://localhost:8080/sockjs-node (webpack)/hot/dev-server.js ./src/main.js

降级

Yarn

$ yarn add -D vue-loader@14.2.3

Npm

$ npm i vue-loader@14.2.3 --save-dev

你好,由于不兼容vuecli3、webpack4、es6的报错:“Cannot assign to read only property 'exports' of object '#'”,请问您有什么好的解决办法么?本地我改下源码就行,发布到线上怎么办呢?

Sessionh commented 5 years ago

找到 babel.config.js 文件加入以下代码:

module.exports = { presets: [ '@vue/app' ], sourceType: 'unambiguous' // 关键是这一句 }

原因分析:

在新的webpack已经不允许 import 和 module.exports 共存,但是我这段代码刚好就这么写了,导致浏览器报错!这时就需要这只babel,sourceType来猜测类进行转码。

airyland commented 5 years ago

vux-loader 已经迁移到 vux 版本库里,并且发布为 @vux/loader,请参照这里 https://github.com/airyland/vux/issues/3430

alex374 commented 5 years ago

npm install babel-plugin-import --save-dev 然后在 babel.config.js 下增加plugin: module.exports = { presets: [ '@vue/app', ], plugins: [ ['import', { libraryName: 'vux', libraryDirectory: 'src/components' }], ], };