1.创建项目

  1. weexpack create weexapp

2.安装必要插件

  1. npm i jwt-simple vue-resource vue-router vuex vuex-router-sync weex-ui -S
  2.  
  3. npm i babel-plugin-component babel-preset-stage-0 history quick-local-ip weex-builder weex-router -D

3.修改 scripts 指令

package.json

  1. "scripts": {
  2. "build": "webpack",
  3. "build_plugin": "webpack --config ./tools/webpack.config.plugin.js --color",
  4. "dev": "webpack --config webpack.config.js --watch",
  5. "serve": "webpack-dev-server --config webpack.dev.js --progress --watch --open",
  6. "start": "webpack && webpack-dev-server --config webpack.dev.js --progress --watch --open",
  7. "create": "weexpack run android"
  8. },

4.配置 weex-ui

.babelrc

  1. {
  2. "presets": ["es2015", "stage-0"],
  3. "plugins": [
  4. [
  5. "component",
  6. {
  7. "libraryName": "weex-ui",
  8. "libDir": "packages"
  9. }
  10. ]
  11. ]
  12. }

5.修改 webpack 模块管理

webpack.config.js

步骤一:

步骤二:

步骤三:

步骤四:

步骤五:

修改后:

webpack.config.js

  1. const pathTo = require('path');
  2. const fs = require('fs-extra');
  3. const webpack = require('webpack');
  4.  
  5. const entry = {index: pathTo.resolve('src', 'entry.js')};
  6. const weexEntry = {index: pathTo.resolve('src', 'entry.js')};
  7. const vueWebTemp = 'temp';
  8. const hasPluginInstalled = fs.existsSync('./web/plugin.js');
  9. var isWin = /^win/.test(process.platform);
  10.  
  11. function getEntryFileContent(entryPath, vueFilePath) {
  12. let relativePath = pathTo.relative(pathTo.join(entryPath, '../'), vueFilePath);
  13. let contents = '';
  14. if (hasPluginInstalled) {
  15. const plugindir = pathTo.resolve('./web/plugin.js');
  16. contents = 'require(\'' + plugindir + '\') \n';
  17. }
  18. if (isWin) {
  19. relativePath = relativePath.replace(/\\/g,'\\\\');
  20. }
  21. contents += 'var App = require(\'' + relativePath + '\')\n';
  22. contents += 'App.el = \'#root\'\n';
  23. contents += 'new Vue(App)\n';
  24. return contents;
  25. }
  26.  
  27. var fileType = '';
  28.  
  29. function walk(dir) {
  30. dir = dir || '.';
  31. const directory = pathTo.join(__dirname, 'src', dir);
  32. fs.readdirSync(directory)
  33. .forEach((file) => {
  34. const fullpath = pathTo.join(directory, file);
  35. const stat = fs.statSync(fullpath);
  36. const extname = pathTo.extname(fullpath);
  37. const basename = pathTo.basename(fullpath);
  38. if (stat.isFile() && extname === '.vue' && basename != 'App.vue' ) {
  39. if (!fileType) {
  40. fileType = extname;
  41. }
  42. if (fileType && extname !== fileType) {
  43. console.log('Error: This is not a good practice when you use ".we" and ".vue" togither!');
  44. }
  45. const name = pathTo.join(dir, pathTo.basename(file, extname));
  46. if (extname === '.vue') {
  47. const entryFile = pathTo.join(vueWebTemp, dir, pathTo.basename(file, extname) + '.js');
  48. fs.outputFileSync(pathTo.join(entryFile), getEntryFileContent(entryFile, fullpath));
  49.  
  50. entry[name] = pathTo.join(__dirname, entryFile) + '?entry=true';
  51. }
  52. weexEntry[name] = fullpath + '?entry=true';
  53. } else if (stat.isDirectory() && ['build','include','assets','filters','mixins'].indexOf(file) == -1 ) {
  54. const subdir = pathTo.join(dir, file);
  55. walk(subdir);
  56. }
  57. });
  58. }
  59.  
  60. walk();
  61. // web need vue-loader
  62. const plugins = [
  63. new webpack.optimize.UglifyJsPlugin({minimize: true}),
  64. new webpack.BannerPlugin({
  65. banner: '// { "framework": ' + (fileType === '.vue' ? '"Vue"' : '"Weex"') + '} \n',
  66. raw: true,
  67. exclude: 'Vue'
  68. })
  69. ];
  70. const webConfig = {
  71. context: pathTo.join(__dirname, ''),
  72. entry: entry,
  73. output: {
  74. path: pathTo.join(__dirname, 'dist'),
  75. filename: '[name].web.js',
  76. },
  77. module: {
  78. // webpack 2.0
  79. rules: [
  80. {
  81. test: /\.js$/,
  82. use: [{
  83. loader: 'babel-loader',
  84. options: {
  85. presets: ['es2015']
  86. }
  87. }]
  88. },
  89. {
  90. test: /\.css$/,
  91. use: [{
  92. loader: 'css-loader'
  93. }]
  94. },
  95. {
  96. test: /\.vue(\?[^?]+)?$/,
  97. use: [{
  98. loader: 'vue-loader'
  99. }]
  100. }
  101. ]
  102. },
  103. plugins: plugins
  104. };
  105. const weexConfig = {
  106. entry: weexEntry,
  107. output: {
  108. path: pathTo.join(__dirname, 'dist'),
  109. filename: '[name].js',
  110. },
  111. module: {
  112. rules: [
  113. {
  114. test: /\.js$/,
  115. use: [{
  116. loader: 'babel-loader',
  117. }]
  118. },
  119. {
  120. test: /\.vue(\?[^?]+)?$/,
  121. use: [{
  122. loader: 'weex-loader'
  123. }]
  124. },
  125. {
  126. test: /\.we(\?[^?]+)?$/,
  127. use: [{
  128. loader: 'weex-loader'
  129. }]
  130. }
  131. ],
  132. },
  133. plugins: plugins,
  134. };
  135.  
  136. var exports = [webConfig, weexConfig];
  137.  
  138. module.exports = exports;

6.修改 webpack 开发环境文件

webpack.dev.js

  1. const ip = require('quick-local-ip').getLocalIP4();
  2. const configs = require('./webpack.config.js');
  3. const webpack = require('webpack');
  4. const pathTo = require('path');
  5. const chalk = require('chalk');
  6. let config = Array.isArray(configs) ? configs[0] : configs;
  7. config.devServer = {
  8. contentBase: pathTo.join(__dirname, ''),
  9. compress: true,
  10. // hot: true,
  11. host: '0.0.0.0',
  12. public: ip + ':8080/web',
  13. // publicPath: '/dist/',
  14. };
  15. // configs.plugins.push(new webpack.HotModuleReplacementPlugin());
  16. console.log('server is running! Please open ' + chalk.green('http://' + ip + ':8080/web/index.html'));
  17. module.exports = config;

7.提取 weex-ui 组件

项目名称 / index.js

  1. /**
  2. * weex-ui 常用组件
  3. */
  4.  
  5. import Utils from './packages/utils';
  6. import WxcButton from './packages/wxc-button';
  7. import WxcCell from './packages/wxc-cell';
  8. import WxcCheckbox from './packages/wxc-checkbox';
  9. import WxcCheckboxList from './packages/wxc-checkbox-list';
  10. import WxcCountdown from './packages/wxc-countdown';
  11. import WxcDialog from './packages/wxc-dialog';
  12. import WxcEpSlider from './packages/wxc-ep-slider';
  13. import WxcPanItem from './packages/wxc-pan-item';
  14. import WxcGridSelect from './packages/wxc-grid-select';
  15. import WxcIndexlist from './packages/wxc-indexlist';
  16. import WxcLightbox from './packages/wxc-lightbox';
  17. import WxcLoading from './packages/wxc-loading';
  18. import WxcPartLoading from './packages/wxc-part-loading';
  19. import WxcMask from './packages/wxc-mask';
  20. import WxcMinibar from './packages/wxc-minibar';
  21. import WxcLotteryRain from './packages/wxc-lottery-rain';
  22. import WxcNoticebar from './packages/wxc-noticebar';
  23. import WxcOverlay from './packages/wxc-overlay';
  24. import WxcPageCalendar from './packages/wxc-page-calendar';
  25. import WxcPopup from './packages/wxc-popup';
  26. import WxcProgress from './packages/wxc-progress';
  27. import WxcRadio from './packages/wxc-radio';
  28. import WxcResult from './packages/wxc-result';
  29. import WxcRichText from './packages/wxc-rich-text';
  30. import WxcSpecialRichText from './packages/wxc-special-rich-text';
  31. import WxcSearchbar from './packages/wxc-searchbar';
  32. import WxcSimpleFlow from './packages/wxc-simple-flow';
  33. import WxcSlideNav from './packages/wxc-slide-nav';
  34. import WxcSliderBar from './packages/wxc-slider-bar';
  35. import WxcStepper from './packages/wxc-stepper';
  36. import WxcTabPage from './packages/wxc-tab-page';
  37. import WxcTabBar from './packages/wxc-tab-bar';
  38. import WxcTag from './packages/wxc-tag';
  39.  
  40. export {
  41. Utils,
  42. WxcButton,
  43. WxcCell,
  44. WxcCheckbox,
  45. WxcCheckboxList,
  46. WxcCountdown,
  47. WxcDialog,
  48. WxcEpSlider,
  49. WxcPanItem,
  50. WxcGridSelect,
  51. WxcIndexlist,
  52. WxcLightbox,
  53. WxcLoading,
  54. WxcPartLoading,
  55. WxcMask,
  56. WxcMinibar,
  57. WxcLotteryRain,
  58. WxcNoticebar,
  59. WxcOverlay,
  60. WxcPageCalendar,
  61. WxcPopup,
  62. WxcProgress,
  63. WxcRadio,
  64. WxcResult,
  65. WxcRichText,
  66. WxcSpecialRichText,
  67. WxcSearchbar,
  68. WxcSimpleFlow,
  69. WxcSlideNav,
  70. WxcSliderBar,
  71. WxcStepper,
  72. WxcTabPage,
  73. WxcTabBar,
  74. WxcTag
  75. };

.

weexapp 开发流程(一)开发环境配置的更多相关文章

  1. Xamarin Anroid开发教程之验证环境配置是否正确

    Xamarin Anroid开发教程之验证环境配置是否正确 经过前面几节的内容已经把所有的编程环境设置完成了,但是如何才能确定所有的一切都处理争取并且没有任何错误呢?这就需要使用相应的实例来验证,本节 ...

  2. 使用EmBitz开发STM32项目的环境配置

    一.EmBitz软件获取与安装 1.EmBitz软件的获取 EmBitz原名Em::Blocks,是基于Code::Blocks开发的,面向嵌入式的C/C++集成开发环境.支持J-Link和ST-Li ...

  3. PHP开发:Eclipse版环境配置

    软件: 1.eclipse php版本下载地址:http://www.eclipse.org/downloads/packages/eclipse-php-developers/heliosr 2.A ...

  4. Dapr微服务应用开发系列1:环境配置

    题记:上篇Dapr系列文章简要介绍了Dapr,这篇来谈一下开发和运行环境配置 本机开发环境配置 安装Docker 为了方便进行Dapr开发,最好(其实不一定必须)首先在本机(开发机器)上安装Docke ...

  5. weex 开发踩坑日记--环境配置、安卓运行、adb、开发

    环境配置方面 1.需要安装java和android环境,java的话一定要下载jdk而不是jre. 在"系统变量"新建一个变量名为JAVA_HOME的变量,变量值为你本地java的 ...

  6. Android开发快速入门(环境配置、Android Studio安装)

    Android是一种激动人心的开源移动平台,它像手机一样无处不在,得到了Google以及其他一些开放手机联盟成员(如三星.HTC.中国移动.Verizon和AT&T等)的支持,因而不能不加以学 ...

  7. 开发流程和Maven的配置

    按照何种开发模型? V模型:项目需求--->概要设计(功能模块) --->详细设计(页面的设计,数据库的设计) --->编码(框架的搭建,功能的实现)---->测试(单元测试, ...

  8. MapReduce开发程序,运行环境配置

    Hadoop主机:linux 开发环境主机:Win7 + Itellij 本地运行 1. 下载hadoop安装包,放到本地目录中. 2. 配置环境变量$HADOOP_HOME及$PATH=$HADOO ...

  9. Andriod开发 --插件安装、环境配置、问题集锦

    1.用Eclipse搭建Android开发环境和创建第一个Android项目(Windows平台) 链接阅读http://www.cnblogs.com/allenzheng/archive/2012 ...

  10. Stardew Valley(星露谷物语)Mod开发之路 1环境配置

    首先来说明一下,我写这个章节本身也是对学习过程的记录,主要参考了http://canimod.com/guides/creating-a-smapi-mod中的内容.也推荐大家看看. *这些是我的开发 ...

随机推荐

  1. leepcode作业解析 - 5-19

    18.两数之和II -输入有序数组 给定一个已按照升序排列 的有序数组,找到两个数使得它们相加之和等于目标数. 函数应该返回这两个下标值 index1 和 index2,其中 index1 必须小于 ...

  2. LeetCode(107) Binary Tree Level Order Traversal II

    题目 Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from l ...

  3. PAT Basic 1045

    1045 快速排序 著名的快速排序算法里有一个经典的划分过程:我们通常采用某种方法取一个元素作为主元,通过交换,把比主元小的元素放到它的左边,比主元大的元素放到它的右边. 给定划分后的 N 个互不相同 ...

  4. sql存储过程打印图形

    print '三角形' declare @a int set @a=1 while(@a<10) begin print replace(space(@a),' ','*') set @a=@a ...

  5. 【LeetCode】Integer to Roman(整数转罗马数字)

    这道题是LeetCode里的第12道题. 吐了,刚做完"罗马数字转整数",现在又做这个.这个没什么想法,只能想到使用if语句嵌套,或者使用哈希表.但哈希表我还不熟练啊.先拿if嵌套 ...

  6. NYOJ 745 首尾相连数组的最大子数组和

    首尾相连数组的最大子数组和 时间限制:1000 ms  |  内存限制:65535 KB 难度:4   描述 给定一个由N个整数元素组成的数组arr,数组中有正数也有负数,这个数组不是一般的数组,其首 ...

  7. 紫书第五章训练2 F - Compound Words

    F - Compound Words You are to find all the two-word compound words in a dictionary. A two-word compo ...

  8. "sort open failed +1 no such file or directory"解决方

    GNU的sort也认老式字段规格: +n.m. 但是字段和字符都从0开始计, 例如-k3 -k2可以等效为+2 -3 +1 -2. 目前使用的sort+和-必须成对使用, 只用+就会报错说”sort: ...

  9. Ubuntu Flask安装与配置(待整理)

    工作中开发需要用到python的flask框架,无奈网络上的资源很少,连基本的安装和配置都不全,在这做一下整理,方便以后用到. ———————————————————————————— 由于比较繁琐, ...

  10. [POJ1143]Number Game

    [POJ1143]Number Game 试题描述 Christine and Matt are playing an exciting game they just invented: the Nu ...