Giter Site home page Giter Site logo

vue-cli-multipage's Introduction

vue-cli多页面

更新

  1. css autoprefix的问题 @luchanan的方案,具体可以参考https://github.com/luchanan/vue2.0-multi-page

  2. Issues#22多页面多路由进入子路由页面直接刷新出错 @Deguang提到需要做http server配置,文档地址http://router.vuejs.org/zh-cn/essentials/history-mode.html 我在dev-server.js中简单得修改了以下代码

// handle fallback for HTML5 history API
app.use(require('connect-history-api-fallback')({
  rewrites: [
    { from: /\/add$/, to: '/module/index.html'},
    { from: /\/list$/, to: '/module/index.html'}
  ]
}))
  1. [Issues#21build之后的vendor.js把所有页面引入的库都放进去了]#21

以下修改方法并没有解决根本问题,只能控制vendor.js不会加载所有node_modules中的模块

在webpack.prod.conf.js中修改

// split vendor js into its own file
new webpack.optimize.CommonsChunkPlugin({
  name: 'vendor',
  minChunks: function (module, count) {
    // any required modules inside node_modules are extracted to vendor
    return (
      module.resource &&
      /\.js$/.test(module.resource) &&
      module.resource.indexOf(
        path.join(__dirname, '../node_modules')
      ) === 0
    )
  }
})

改为

new webpack.optimize.CommonsChunkPlugin({
    name: 'vendors', // 将公共模块提取,生成名为`vendors`的chunk
    chunks: ['index','info'], //提取哪些模块共有的部分
    minChunks: 2 // 提取至少2个模块共有的部分
})

A Vue.js project

Build Setup

# install dependencies
npm install

# serve with hot reload at localhost:8080
npm run dev

# build for production with minification
npm run build

# run unit tests
npm run unit

# run e2e tests
npm run e2e

# run all tests
npm test

多页面配置

vue2.0版本多页面入口,是由webpack配置来完成的 比如说,我的项目文件结构如下

    webpack
      |---build
      |---src
        |---assets 资源
        |---components组件
        |---module各个模块
          |---index    index模块
            |---index.html
            |---index.js
            |---index.vue
          |---info       info模块
            |---info.html
            |---info.js
            |---info.vue

修改webpack.base.conf.js文件

var glob = require('glob'); //这里的glob是nodejs的glob模块,是用来读取webpack入口目录文件的
var entries = getEntry('./src/module/**/*.js'); // 获得入口js文件
function getEntry(globPath) {
  var entries = {},
      basename, tmp, pathname;

  glob.sync(globPath).forEach(function (entry) {
    basename = path.basename(entry, path.extname(entry));
    tmp = entry.split('/').splice(-3);
    pathname = tmp.splice(0, 1) + '/' + basename; // 正确输出js和html的路径
    entries[pathname] = entry;
  });
  console.log(entries);
  return entries;
}

module.exports = {
  entry: entries,
  ***
}

修改webpack.dev.conf.js文件

var glob = require('glob');
module.exports = merge(baseWebpackConfig, {
  devtool: '#eval-source-map',
  plugins: [
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin()
  ]
})

function getEntry(globPath) {
  var entries = {},
    basename, tmp, pathname;

  glob.sync(globPath).forEach(function (entry) {
    basename = path.basename(entry, path.extname(entry));
    tmp = entry.split('/').splice(-3);
    pathname = tmp.splice(0, 1) + '/' + basename; // 正确输出js和html的路径
    entries[pathname] = entry;
  });
  console.log(entries);
  return entries;
}

var pages = getEntry('./src/module/**/*.html');

for (var pathname in pages) {
  // 配置生成的html文件,定义路径等
  var conf = {
    filename: pathname + '.html',
    template: pages[pathname], // 模板路径
    chunks: [pathname, 'vendor', 'manifest'], // 每个html引用的js模块
    inject: true              // js插入位置
  };
  // 需要生成几个html文件,就配置几个HtmlWebpackPlugin对象
  module.exports.plugins.push(new HtmlWebpackPlugin(conf));
}

修改webpack.prod.conf.js文件

var glob = require('glob');
module.exports = merge(baseWebpackConfig, {
  ***
  plugins: [
    ***
    new webpack.optimize.OccurenceOrderPlugin(),
    new ExtractTextPlugin(path.join(config.build.assetsSubDirectory, '[name].[contenthash].css'))
  ]
})

function getEntry(globPath) {
  var entries = {},
    basename, tmp, pathname;

  glob.sync(globPath).forEach(function (entry) {
    basename = path.basename(entry, path.extname(entry));
    tmp = entry.split('/').splice(-3);
    pathname = tmp.splice(0, 1) + '/' + basename; // 正确输出js和html的路径
    entries[pathname] = entry;
  });
  console.log(entries);
  return entries;
}

var pages = getEntry('./src/module/**/*.html');

for (var pathname in pages) {
  console.log(pathname);
  // 配置生成的html文件,定义路径等
  var conf = {
    // filename: pathname + '.html',
    filename: pathname + '.html',
    template: pages[pathname], // 模板路径
    chunks: [pathname, 'vendor', 'manifest'], // 每个html引用的js模块
    inject: true              // js插入位置
  };
  // 需要生成几个html文件,就配置几个HtmlWebpackPlugin对象
  module.exports.plugins.push(new HtmlWebpackPlugin(conf));
}

参考

vue-router2.0 luchanan的vue多页面配置

vue-cli-multipage's People

Contributors

yaoyao1987 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-cli-multipage's Issues

设置proxyTable失效

  dev: {
    env: require('./dev.env'),
    port: 8080,
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {
      '/module/info.html': {
        target: 'http://localhost:8000',
        changeOrigin: true
      }
    }

不能访问 http://localhost:8080/module/info.html

在vue组件里使用saas会报错

<style lang='scss'> $colorFe:#ff6633 #list { display: flex; color:$colorFe } #pre{ transform: translate(0,0); } </style>

报错:
Invalid CSS after "#list": expected 1 selector or at-rule, was "{"
in D:\vue-cli-multipage-master\src\module\index\list.vue (line 17, col

安装报错了。。。

Error: connect ETIMEDOUT 173.194.72.128:80
at Object.exports._errnoException (util.js:1026:11)
at exports._exceptionWithHostPort (util.js:1049:20)
at TCPConnectWrap.afterConnect as oncomplete
npm WARN [email protected] requires a peer of babel-runtime@^6.0.0 but none was installed.
npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.
npm ERR! Darwin 14.5.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v6.4.0
npm ERR! npm v3.10.3
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: node install.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script 'node install.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the chromedriver package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node install.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs chromedriver
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls chromedriver
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! /Users/WRQ/Git/vue-cli-multipage/npm-debug.log

Failed to load resource: the server responded with a status of 404 (Not Found)

你好,我照你说的做;怎么页面没显示,哪点信息配置错了。。。
webpack: wait until bundle finished: /index.html
webpack: wait until bundle finished: /favicon.ico
webpack built 1671c54f98ff6da2bbe6 in 6673ms
Hash: 1671c54f98ff6da2bbe6
Version: webpack 1.13.3
Time: 6673ms
Asset Size Chunks Chunk Names
module/index.js 1.03 MB 0 [emitted] module/index
module/info.js 897 kB 1 [emitted] module/info
module/index.html 558 bytes [emitted]
module/info.html 306 bytes [emitted]
Child html-webpack-plugin for "module\index.html":
Asset Size Chunks Chunk Names
module/index.html 1.47 MB 0
Child html-webpack-plugin for "module\info.html":
Asset Size Chunks Chunk Names
module/info.html 1.47 MB 0
webpack: bundle is now VALID.

npm run build 构建报错!

在 webpack.prod.conf.js 文件里, 最后导出 module.exports = webpackConfig,
而在此之前却已经调用 module.exports.plugins.push(new HtmlWebpackPlugin(conf)),

故解决防范 可以 去掉 module.exports = webpackConfig,
.... 在 var webpackConfig = merge(baseWebpackConfig, {

改为 module.exports = merge(baseWebpackConfig, {

怎么不启用vue-tools

打包之后,生产环境还是可以看到vue-tools. 但是,webpack.prod.conf.js 里引用的env 是 NODE_ENV: '"production"'

请教一下

现在我们公司有多个产品,我们想这样做:
每个产品是一个spa,每个产品自己构建编译,这样就不用一个产品改动,全部都要编译了,然后外层框架提供公共组件和公共部分的界面,比如顶部导航和左侧菜单,点击左侧菜单,中间内容区进入不同的spa应用,一种方案是iframe(被否决了),另一种是公共界面作为组件引入到子产品里面,不知道还有没有更好的方法呢?

求助

大神能按照Vue新的版本的基础上改造一个您这样的吗?
QQ:285965920

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.