Giter Club home page Giter Club logo

webpack-mutiple's Introduction

webpack-mutiple

vue多页面开发脚手架

vue官方只提供了单页面的脚手架,但我们可以根据它来改造成多页面,开发的时候我们每次只开发一个页面,而不是同时开发多个页面,所以项目根路径下应该有个配置js,来指明这次要开发的页面

工具推荐

  1. 最新版webstorm
  2. 使用yarn安装依赖(提供lock功能) 国内用户请使用淘宝源
    yarn config set registry https://registry.npm.taobao.org
  3. node-sass安装失败解决方案 SASS_BINARY_SITE=https://npm.taobao.org/mirrors/node-sass/ npm install node-sass

使用

这是一个vue-cli.的项目模板

$ npm install -g vue-cli
$ vue init agileago/webpack-mutiple my-project
$ cd my-project
$ npm install (或者 yarn)
$ npm run vendor
$ npm run dev
$ npm run build

多页面如何配置

配置在config.js里面

/**
 * 需要构建的页面 一次只构建一个页面
 */
const pageName = 'index'

// 大部分情况下都是默认配置

const notUseVendor = []          // 不使用公共资源的页面集合
const notExtractCss = []         // 不抽取css的页面
const useAbsolutePath = {        // 使用绝对路径的页面
  example: '//cdn.com/'
}

module.exports = {
  pageName: pageName,
  useVendor: notUseVendor.indexOf(pageName) === -1,           // 是否使用公共资源 需要先运行 np run vendor
  extractCss: notExtractCss.indexOf(pageName) === -1,           // 是否抽取出css
  // 资源引用路径是否为绝对路径 默认为相对路径
  // cdn 地址 绝对路径的地址 如果没有cdn域名请填写 / 默认是相对路径 false
  absolutePath: useAbsolutePath[pageName] == undefined ? false : useAbsolutePath[pageName],
  sourceMap: false,           //  生产环境下是否需要js生成sourceMap
  browsers: ['ios > 7', 'android > 4.1']
}

公共资源 vendor

多个页面需要共享资源库,利用webpack的dll功能生成vendor, vendor的配置在 package.json中的vendor选项

"vendor": [
  "vue",
  "es6-promise",
  "weui"
],

生成页面

每做一个新页面需要在src/views/下面生成一个页面文件夹,文件夹里面需要包含一个入口文件 main.js 和页面模板文件 template.html,具体请看index示例页面

tips

当想在工程里面引入node_modules下工程某些源代码,但这些源代码有可能是es6语法的,可直接在webpack的 loader里面添加

{
  test: /vux.src.*?js$/,
  loader: 'babel-loader'
}

就是模块名 . 源码文件夹 js文件

webpack-mutiple's People

Contributors

agileago avatar fugangqiang 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

webpack-mutiple's Issues

问题

  1. css开发环境与生产环境postcss前缀不一致 这可能是webpack的一个Bug
  2. 公共css打包的功能未实践

vue-router Html5 模式下报错。

使用html5模式
routes: [ { path: '/shopred/:id', name: 'index', props:true, component: index, meta: { title: '首页--到店红包' } } ]

访问localhost:8080/shopred/1 报以下错误

GET http://localhost:8081/shopred/lib/vendor/vendor.common.css 1:17 GET http://localhost:8081/shopred/lib/vendor/vendor.common.js external "vendor_common":1 Uncaught ReferenceError: vendor_common is not defined at Object.zjZD (external "vendor_common":1) at __webpack_require__ (bootstrap 13c1e111ad9699d3c9e1:677) at fn (bootstrap 13c1e111ad9699d3c9e1:87) at Object./5sW (vue.runtime.esm.js from dll-reference vendor_common:1) at __webpack_require__ (bootstrap 13c1e111ad9699d3c9e1:677) at fn (bootstrap 13c1e111ad9699d3c9e1:87) at Object.LqED (app.js:1495) at __webpack_require__ (bootstrap 13c1e111ad9699d3c9e1:677) at fn (bootstrap 13c1e111ad9699d3c9e1:87) at Object.0 (app.js:747)

不使用html5模式就正常

请教

很感谢您的代码,但是我在npm run dev 的时候回报错,新手请教
$ npm run dev

[email protected] dev /Volumes/OS-DATA/WorkSpace/PhpSpace/truesign/apps_front
node build/server.js

module.js:474
throw err;
^

Error: Cannot find module '../manifest.json'
at Function.Module._resolveFilename (module.js:472:15)
at Function.Module._load (module.js:420:25)
at Module.require (module.js:500:17)
at require (internal/module.js:20:19)
at Object. (/Volumes/OS-DATA/WorkSpace/PhpSpace/truesign/apps_front/build/webpack.base.js:50:15)
at Module._compile (module.js:573:32)
at Object.Module._extensions..js (module.js:582:10)
at Module.load (module.js:490:32)
at tryModuleLoad (module.js:449:12)
at Function.Module._load (module.js:441:3)

npm ERR! Darwin 16.1.0
npm ERR! argv "/usr/local/Cellar/node/7.0.0/bin/node" "/usr/local/bin/npm" "run" "dev"
npm ERR! node v7.0.0
npm ERR! npm v3.10.8
npm ERR! code ELIFECYCLE
npm ERR! [email protected] dev: node build/server.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] dev script 'node build/server.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 webpack-mutiple package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node build/server.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs webpack-mutiple
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls webpack-mutiple
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! /Volumes/OS-DATA/WorkSpace/PhpSpace/truesign/apps_front/npm-debug.log

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.