F-loat / mpvue-entry

⛓️ 集中式页面配置,统一构建入口,支持新增页面热更新
MIT License
352 stars 56 forks source link

哥有没有适配mpvue2.0的计划 #108

Open fengzhiqiang012 opened 5 years ago

fengzhiqiang012 commented 5 years ago

megalo 总感觉编译很慢

F-loat commented 5 years ago

最新版支持 mpvue2.0 的,使用中具体有什么问题吗

fengzhiqiang012 commented 5 years ago

最新版支持 mpvue2.0 的,使用中具体有什么问题吗

好的 哥, 我看你没写 就没去试 还是用的以前的 等下我去迁移试试

fengzhiqiang012 commented 5 years ago

最新版支持 mpvue2.0 的,使用中具体有什么问题吗

哥,报错 const importNode = astPath.node.specifiers[0].local; ^

TypeError: Cannot read property 'local' of undefined

用的官方最新的quickstart 然后接你的报错

F-loat commented 5 years ago

main.js 发一下

fengzhiqiang012 commented 5 years ago

main.js 发一下

解决了,少了个依赖 感谢感谢

tianlinzx commented 5 years ago

哥,既然支持2.0了,能不能把quickstart也相应的更新一下? @fengzhiqiang012

wxymmxf commented 5 years ago

@F-loat @fengzhiqiang012 可以帮忙看看么?不支持mpvue2.0.0,报错:未找到入口页面app.json 中定义的 pages : [] 下面是main.js

import Vue from 'vue'
import store from '@/store'
import App from '@/App'
import './sass/comm.scss'
Vue.config.productionTip = false
Vue.prototype.$store = store
const app = new Vue({
  // store,
  ...App
})
app.$mount()

下面是webpack.base.conf.js

var path = require('path')
var fs = require('fs')
var utils = require('./utils')
var config = require('../config')
var webpack = require('webpack')
var merge = require('webpack-merge')
var vueLoaderConfig = require('./vue-loader.conf')
var MpvuePlugin = require('webpack-mpvue-asset-plugin')
var glob = require('glob')
var CopyWebpackPlugin = require('copy-webpack-plugin')
var relative = require('relative')
const MpvueEntry = require('mpvue-entry')
function resolve (dir) {
  return path.join(__dirname, '..', dir)
}

function getEntry (rootSrc) {
  var map = {};
  glob.sync(rootSrc + '/pages/**/main.js')
  .forEach(file => {
    var key = relative(rootSrc, file).replace('.js', '');
    map[key] = file;
  })
   return map;
}

const appEntry = { app: resolve('./src/main.js') }
const pagesEntry = getEntry(resolve('./src'), 'pages/**/main.js')
const entry = Object.assign({}, appEntry, pagesEntry)

let baseWebpackConfig = {
  // 如果要自定义生成的 dist 目录里面的文件路径,
  // 可以将 entry 写成 {'toPath': 'fromPath'} 的形式,
  // toPath 为相对于 dist 的路径, 例:index/demo,则生成的文件地址为 dist/index/demo.js
  entry: MpvueEntry.getEntry('src/pages.js'),
  target: require('mpvue-webpack-target'),
  output: {
    path: config.build.assetsRoot,
    jsonpFunction: 'webpackJsonpMpvue',
    filename: '[name].js',
    publicPath: process.env.NODE_ENV === 'production'
      ? config.build.assetsPublicPath
      : config.dev.assetsPublicPath
  },
  resolve: {
    extensions: ['.js', '.vue', '.json'],
    alias: {
      'vue': 'mpvue',
      '@': resolve('src'),
      'flyio': 'flyio/dist/npm/wx',
      'wx': resolve('src/api/wx')
    },
    symlinks: false,
    aliasFields: ['mpvue', 'weapp', 'browser'],
    mainFields: ['browser', 'module', 'main']
  },
  module: {
    rules: [
      {
        test: /\.(js|vue)$/,
        loader: 'eslint-loader',
        enforce: 'pre',
        include: [resolve('src'), resolve('test')],
        options: {
          formatter: require('eslint-friendly-formatter')
        }
      },
      {
        test: /\.vue$/,
        loader: 'mpvue-loader',
        options: vueLoaderConfig
      },
      {
        test: /\.js$/,
        include: [resolve('src'), resolve('test')],
        use: [
          'babel-loader',
          {
            loader: 'mpvue-loader',
            options: Object.assign({checkMPEntry: true}, vueLoaderConfig)
          },
        ]
      },
      {
        test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
        loader: 'url-loader',
        options: {
          limit: 10000,
          name: utils.assetsPath('img/[name].[ext]')
        }
      },
      {
        test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
        loader: 'url-loader',
        options: {
          limit: 10000,
          name: utils.assetsPath('media/[name].[ext]')
        }
      },
      {
        test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
        loader: 'url-loader',
        options: {
          limit: 10000,
          name: utils.assetsPath('fonts/[name].[ext]')
        }
      }
    ]
  },
  plugins: [
    new MpvueEntry(),
    // api 统一桥协议方案
    new webpack.DefinePlugin({
      'mpvue': 'global.mpvue',
      'mpvuePlatform': 'global.mpvuePlatform'
    }),
    new MpvuePlugin(),
    new CopyWebpackPlugin([
      {
        from: path.resolve(__dirname, '../static'),
        to: path.resolve(config.build.assetsRoot, './static'),
        ignore: ['.*']
      }
    ])
  ]
}

// 针对百度小程序,由于不支持通过 miniprogramRoot 进行自定义构建完的文件的根路径
// 所以需要将项目根路径下面的 project.swan.json 拷贝到构建目录
// 然后百度开发者工具将 dist/swan 作为项目根目录打
const projectConfigMap = {
  tt: '../project.config.json',
  swan: '../project.swan.json'
}

const PLATFORM = process.env.PLATFORM
if (/^(swan)|(tt)$/.test(PLATFORM)) {
  baseWebpackConfig = merge(baseWebpackConfig, {
    plugins: [
      new CopyWebpackPlugin([{
        from: path.resolve(__dirname, projectConfigMap[PLATFORM]),
        to: path.resolve(config.build.assetsRoot)
      }])
    ]
  })
}

module.exports = baseWebpackConfig
F-loat commented 5 years ago

提问请具体一点,可以复现才能帮你解决

F-loat commented 5 years ago

发下 pages.js 的内容

F-loat commented 5 years ago

看下 readme,mpvue-entry@2.x 调整了下这个文件的格式

wxymmxf commented 5 years ago

看下 readme,mpvue-entry@2.x 调整了下这个文件的格式

收到!我马上试试,多谢

wxymmxf commented 5 years ago

看下 readme,mpvue-entry@2.x 调整了下这个文件的格式

感谢大神!修改了入口为app.json,已经ok了,多谢多谢!

muzixiaojun commented 5 years ago

看下 readme,mpvue-entry@2.x 调整了下这个文件的格式

感谢大神!修改了入口为app.json,已经ok了,多谢多谢!

能把你配置的给我看下吗?我也是你之前的问题,可是我改了入口为app.json,直接不能编译

muzixiaojun commented 5 years ago

webpack.base.conf.js var path = require('path') var fs = require('fs') var utils = require('./utils') var config = require('../config') var webpack = require('webpack') var merge = require('webpack-merge') var vueLoaderConfig = require('./vue-loader.conf') var MpvuePlugin = require('webpack-mpvue-asset-plugin') var glob = require('glob') var CopyWebpackPlugin = require('copy-webpack-plugin') var relative = require('relative') const MpvueEntry = require('mpvue-entry') function resolve (dir) { return path.join(__dirname, '..', dir) } // // function getEntry (rootSrc) { // var map = {}; // glob.sync(rootSrc + '/pages/**/main.js') // .forEach(file => { // var key = relative(rootSrc, file).replace('.js', ''); // map[key] = file; // }) // return map; // } // // const appEntry = { app: resolve('./src/app.json') } // const pagesEntry = MpvueEntry.getEntry('./src/router/index.js') // const entry = Object.assign({}, appEntry, pagesEntry)

let baseWebpackConfig = { // 如果要自定义生成的 dist 目录里面的文件路径, // 可以将 entry 写成 {'toPath': 'fromPath'} 的形式, // toPath 为相对于 dist 的路径, 例:index/demo,则生成的文件地址为 dist/index/demo.js // entry, entry: MpvueEntry.getEntry('src/app.json'), target: require('mpvue-webpack-target'), output: { path: config.build.assetsRoot, jsonpFunction: 'webpackJsonpMpvue', filename: '[name].js', publicPath: process.env.NODE_ENV === 'production' ? config.build.assetsPublicPath : config.dev.assetsPublicPath }, resolve: { extensions: ['.js', '.vue', '.json'], alias: { 'vue': 'mpvue', '@': resolve('src') }, symlinks: false, aliasFields: ['mpvue', 'weapp', 'browser'], mainFields: ['browser', 'module', 'main'] }, module: { rules: [ { test: /.(js|vue)$/, loader: 'eslint-loader', enforce: 'pre', include: [resolve('src'), resolve('test')], options: { formatter: require('eslint-friendly-formatter') } }, { test: /.vue$/, loader: 'mpvue-loader', options: vueLoaderConfig }, { test: /.js$/, include: [resolve('src'), resolve('test')], use: [ 'babel-loader', { loader: 'mpvue-loader', options: Object.assign({checkMPEntry: true}, vueLoaderConfig) }, ] }, { test: /.(png|jpe?g|gif|svg)(\?.)?$/, loader: 'url-loader', options: { limit: 10000, name: utils.assetsPath('img/[name].[ext]') } }, { test: /.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.)?$/, loader: 'url-loader', options: { limit: 10000, name: utils.assetsPath('media/[name].[ext]') } }, { test: /.(woff2?|eot|ttf|otf)(\?.*)?$/, loader: 'url-loader', options: { limit: 10000, name: utils.assetsPath('fonts/[name].[ext]') } } ] }, plugins: [ // api 统一桥协议方案 new webpack.DefinePlugin({ 'mpvue': 'global.mpvue', 'mpvuePlatform': 'global.mpvuePlatform' }), new MpvuePlugin(), new MpvueEntry(), // new CopyWebpackPlugin([{ // from: '*/.json', // to: '' // }], { // context: 'src/' // }), new CopyWebpackPlugin([ { from: path.resolve(__dirname, '../static'), to: path.resolve(config.build.assetsRoot, './static'), ignore: ['.*'] } ]) ] }

// 针对百度小程序,由于不支持通过 miniprogramRoot 进行自定义构建完的文件的根路径 // 所以需要将项目根路径下面的 project.swan.json 拷贝到构建目录 // 然后百度开发者工具将 dist/swan 作为项目根目录打 const projectConfigMap = { tt: '../project.config.json', swan: '../project.swan.json' }

const PLATFORM = process.env.PLATFORM if (/^(swan)|(tt)$/.test(PLATFORM)) { baseWebpackConfig = merge(baseWebpackConfig, { plugins: [ new CopyWebpackPlugin([{ from: path.resolve(__dirname, projectConfigMap[PLATFORM]), to: path.resolve(config.build.assetsRoot) }]) ] }) }

module.exports = baseWebpackConfig

muzixiaojun commented 5 years ago

pages.js

module.exports = [ { path: 'pages/index/index', name: 'Index', config: { navigationBarTitleText: 'zhuye' } }, { path: 'pages/test1/index', name: 'Test1', config: { navigationBarTitleText: 'list详情', usingComponents: { 'i-button': '../../static/iview/button/index' } } }, { path: 'pages/list/index', name: 'List', config: { navigationBarTitleText: 'zzzzzzz7777' } } ]

muzixiaojun commented 5 years ago

我的package.json里的 mpvue-loader: '^2.0.0' "mpvue-entry": "^1.5.9" 还需要什么?我提供 或者哪位大神QQ发给我 指导我一下

F-loat commented 5 years ago

@muzixiaojun 用最新版的 mpvue-entry

muzixiaojun commented 5 years ago

@muzixiaojun 用最新版的 mpvue-entry

大神 按照你说的 最新版了,然后是编译起来了,可是报 出现脚本错误或者未正确调用 Page()

muzixiaojun commented 5 years ago

然后需要每个创建的页面 都有main.js吗?因为我点击跳test页面报找不到test的main.js

F-loat commented 5 years ago

@muzixiaojun 原来的 path 为 /pages/test/main 的话,用了这个库之后改成 /pages/test 即可

muzixiaojun commented 5 years ago

我的path就是 /pages/test,所以我也不知道到底是哪里配置错误了,能麻烦加下你QQ,我截图给你看下吗

muzixiaojun commented 5 years ago

现在就是编译后, pages/index.js 出现脚本错误或者未正确调用 Page() 这个是什么情况

F-loat commented 5 years ago

webpack-mpvue-asset-plugin 这个插件更新下试试

muzixiaojun commented 5 years ago

我用是用官方mvpue-cli 搭建的项目。里面的webpack-mpvue-asset-plugin:"^2.0.0",应该是最新版本的把。我也把node_modules全删了,重装,问题还是没有解决

F-loat commented 5 years ago

@muzixiaojun 没有多平台需求的话可以用 https://github.com/F-loat/mpvue-quickstart 这个模板

zjydipingxian commented 5 years ago

按照你的配置信息, npm run dev 起不来

zjydipingxian commented 5 years ago

mpvue,是2.0版本的

F-loat commented 5 years ago

上面那个模板有问题吗?有报错的话发一下

zjydipingxian commented 5 years ago

上面那个模板有问题吗?有报错的话发一下

QQ图片20190401154650

F-loat commented 5 years ago

@zjydipingxian 官方的模板吗,你依赖安装有问题吧

zjydipingxian commented 5 years ago

@zjydipingxian 官方的模板吗,你依赖安装有问题吧

是官方模板搭建, 使用此版本npm i mpvue-entry@next -D, 作者如果方便可以加下我QQ? 方便沟通 1036432890

F-loat commented 5 years ago

@zjydipingxian 你这个是缺依赖,再执行下 npm i 看看,有多平台需求的话推荐你用 uni-app 吧,配置也相对简便很多

zjydipingxian commented 5 years ago

@zjydipingxian 你这个是缺依赖,再执行下 npm i 看看,有多平台需求的话推荐你用 uni-app 吧,配置也相对简便很多

我装了这样呀,就是装了这个我启动不了,现在不考虑多平台。

F-loat commented 5 years ago

@zjydipingxian 不考虑多平台你直接用我提供的模板不就行,我看看是不官方模板缺个依赖 模板没问题

zjydipingxian commented 5 years ago

@zjydipingxian 你这个是缺依赖,再执行下 npm i 看看,有多平台需求的话推荐你用 uni-app 吧,配置也相对简便很多

image

F-loat commented 5 years ago

path 是 vue 文件的路径

zjydipingxian commented 5 years ago

npm install 和 npm i 有区别的?

F-loat commented 5 years ago

没区别,缺依赖你再装一次就行,估计装这个模块的时候被删掉了

zjydipingxian commented 5 years ago

没区别,缺依赖你再装一次就行,估计装这个模块的时候被删掉了

我现在npm i, 然后把文件里面的main.js 删除了 就可以了。

annxsun commented 5 years ago

最新版支持 mpvue2.0 的,使用中具体有什么问题吗

哥,报错 const importNode = astPath.node.specifiers[0].local; ^

TypeError: Cannot read property 'local' of undefined

用的官方最新的quickstart 然后接你的报错

我使用mixin 也报这个错了, 你咋解决的?

annxsun commented 5 years ago
import Vue from 'vue'
import App from '@/App'
import store from '@/store'
import MpvueRouterPatch from 'mpvue-router-patch'
import request from './utils/request'
import './style/common'
Vue.use(MpvueRouterPatch)
Vue.prototype.$store = store
Vue.prototype.$request = request

Vue.mixin({
  computed: {
    $miniAppName: function() {
      return process.env.PROJECT_NAME
    },
    $miniStaticBase: function() {
      return process.env.STATIC_RESOURCE_LOCATION
    }
  }
})

const app = new Vue(App)
app.$mount()

加了 Vue.mixin({}) 就报错了

> mpvue-basic@1.0.0 start C:\workspace\my\mpvue-basic
> node build/dev-server.js

C:\workspace\my\mpvue-basic\node_modules\mpvue-entry\lib\parser\template.js:10
        const importNode = astPath.node.specifiers[0].local;
                                                      ^

TypeError: Cannot read property 'local' of undefined
    at enter (C:\workspace\my\mpvue-basic\node_modules\mpvue-entry\lib\parser\template.js:10:55)
    at NodePath._call (C:\workspace\my\mpvue-basic\node_modules\mpvue-entry\node_modules\@babel\traverse\lib\path\context.js:53:20)
    at NodePath.call (C:\workspace\my\mpvue-basic\node_modules\mpvue-entry\node_modules\@babel\traverse\lib\path\context.js:40:17)
    at NodePath.visit (C:\workspace\my\mpvue-basic\node_modules\mpvue-entry\node_modules\@babel\traverse\lib\path\context.js:88:12)
    at TraversalContext.visitQueue (C:\workspace\my\mpvue-basic\node_modules\mpvue-entry\node_modules\@babel\traverse\lib\context.js:118:16)
    at TraversalContext.visitMultiple (C:\workspace\my\mpvue-basic\node_modules\mpvue-entry\node_modules\@babel\traverse\lib\context.js:85:17)
    at TraversalContext.visit (C:\workspace\my\mpvue-basic\node_modules\mpvue-entry\node_modules\@babel\traverse\lib\context.js:144:19)
    at Function.traverse.node (C:\workspace\my\mpvue-basic\node_modules\mpvue-entry\node_modules\@babel\traverse\lib\index.js:94:17)
    at NodePath.visit (C:\workspace\my\mpvue-basic\node_modules\mpvue-entry\node_modules\@babel\traverse\lib\path\context.js:95:18)
    at TraversalContext.visitQueue (C:\workspace\my\mpvue-basic\node_modules\mpvue-entry\node_modules\@babel\traverse\lib\context.js:118:16)
    at TraversalContext.visitSingle (C:\workspace\my\mpvue-basic\node_modules\mpvue-entry\node_modules\@babel\traverse\lib\context.js:90:19)
    at TraversalContext.visit (C:\workspace\my\mpvue-basic\node_modules\mpvue-entry\node_modules\@babel\traverse\lib\context.js:146:19)
    at Function.traverse.node (C:\workspace\my\mpvue-basic\node_modules\mpvue-entry\node_modules\@babel\traverse\lib\index.js:94:17)
    at traverse (C:\workspace\my\mpvue-basic\node_modules\mpvue-entry\node_modules\@babel\traverse\lib\index.js:76:12)
    at removeImportBySpecifier (C:\workspace\my\mpvue-basic\node_modules\mpvue-entry\lib\parser\template.js:7:3)
    at CallExpression (C:\workspace\my\mpvue-basic\node_modules\mpvue-entry\lib\parser\template.js:71:9)
npm ERR! code ELIFECYCLE
F-loat commented 5 years ago

emmm 先把 mixin 的内容提取到其他文件吧

annxsun commented 5 years ago

emmm 先把 mixin 的内容提取到其他文件吧

好的

LiangFuzhi commented 5 years ago

image image vue init F-loat/mpvue-quickstart my-project生成的项目引用其他文件报错 image

F-loat commented 5 years ago

暂时把 css 的引用放到 App.vue 里

LiangFuzhi commented 5 years ago

image 放在app.vue也是出错,放在main.js把css后缀去掉就不会报错

F-loat commented 5 years ago

style 里引用模块需要加个 ~ 的吧

LiangFuzhi commented 5 years ago

已弃坑,跳进megalo新坑

zhoufanglu commented 4 years ago

楼主少了什么依赖,我跟你报一样的错,使用mixins会这样

zhoufanglu commented 4 years ago

解决了,少了个依赖 感谢感谢

请问少了什么依赖。