1.创建项目

weexpack create weexapp

2.安装必要插件

npm i jwt-simple vue-resource vue-router vuex vuex-router-sync weex-ui -S

npm i babel-plugin-component babel-preset-stage-0 history quick-local-ip weex-builder weex-router -D

3.修改 scripts 指令

package.json

"scripts": {
"build": "webpack",
"build_plugin": "webpack --config ./tools/webpack.config.plugin.js --color",
"dev": "webpack --config webpack.config.js --watch",
"serve": "webpack-dev-server --config webpack.dev.js --progress --watch --open",
"start": "webpack && webpack-dev-server --config webpack.dev.js --progress --watch --open",
"create": "weexpack run android"
},

4.配置 weex-ui

.babelrc

{
"presets": ["es2015", "stage-0"],
"plugins": [
[
"component",
{
"libraryName": "weex-ui",
"libDir": "packages"
}
]
]
}

5.修改 webpack 模块管理

webpack.config.js

步骤一:

步骤二:

步骤三:

步骤四:

步骤五:

修改后:

webpack.config.js

const pathTo = require('path');
const fs = require('fs-extra');
const webpack = require('webpack'); const entry = {index: pathTo.resolve('src', 'entry.js')};
const weexEntry = {index: pathTo.resolve('src', 'entry.js')};
const vueWebTemp = 'temp';
const hasPluginInstalled = fs.existsSync('./web/plugin.js');
var isWin = /^win/.test(process.platform); function getEntryFileContent(entryPath, vueFilePath) {
let relativePath = pathTo.relative(pathTo.join(entryPath, '../'), vueFilePath);
let contents = '';
if (hasPluginInstalled) {
const plugindir = pathTo.resolve('./web/plugin.js');
contents = 'require(\'' + plugindir + '\') \n';
}
if (isWin) {
relativePath = relativePath.replace(/\\/g,'\\\\');
}
contents += 'var App = require(\'' + relativePath + '\')\n';
contents += 'App.el = \'#root\'\n';
contents += 'new Vue(App)\n';
return contents;
} var fileType = ''; function walk(dir) {
dir = dir || '.';
const directory = pathTo.join(__dirname, 'src', dir);
fs.readdirSync(directory)
.forEach((file) => {
const fullpath = pathTo.join(directory, file);
const stat = fs.statSync(fullpath);
const extname = pathTo.extname(fullpath);
const basename = pathTo.basename(fullpath);
if (stat.isFile() && extname === '.vue' && basename != 'App.vue' ) {
if (!fileType) {
fileType = extname;
}
if (fileType && extname !== fileType) {
console.log('Error: This is not a good practice when you use ".we" and ".vue" togither!');
}
const name = pathTo.join(dir, pathTo.basename(file, extname));
if (extname === '.vue') {
const entryFile = pathTo.join(vueWebTemp, dir, pathTo.basename(file, extname) + '.js');
fs.outputFileSync(pathTo.join(entryFile), getEntryFileContent(entryFile, fullpath)); entry[name] = pathTo.join(__dirname, entryFile) + '?entry=true';
}
weexEntry[name] = fullpath + '?entry=true';
} else if (stat.isDirectory() && ['build','include','assets','filters','mixins'].indexOf(file) == -1 ) {
const subdir = pathTo.join(dir, file);
walk(subdir);
}
});
} walk();
// web need vue-loader
const plugins = [
new webpack.optimize.UglifyJsPlugin({minimize: true}),
new webpack.BannerPlugin({
banner: '// { "framework": ' + (fileType === '.vue' ? '"Vue"' : '"Weex"') + '} \n',
raw: true,
exclude: 'Vue'
})
];
const webConfig = {
context: pathTo.join(__dirname, ''),
entry: entry,
output: {
path: pathTo.join(__dirname, 'dist'),
filename: '[name].web.js',
},
module: {
// webpack 2.0
rules: [
{
test: /\.js$/,
use: [{
loader: 'babel-loader',
options: {
presets: ['es2015']
}
}]
},
{
test: /\.css$/,
use: [{
loader: 'css-loader'
}]
},
{
test: /\.vue(\?[^?]+)?$/,
use: [{
loader: 'vue-loader'
}]
}
]
},
plugins: plugins
};
const weexConfig = {
entry: weexEntry,
output: {
path: pathTo.join(__dirname, 'dist'),
filename: '[name].js',
},
module: {
rules: [
{
test: /\.js$/,
use: [{
loader: 'babel-loader',
}]
},
{
test: /\.vue(\?[^?]+)?$/,
use: [{
loader: 'weex-loader'
}]
},
{
test: /\.we(\?[^?]+)?$/,
use: [{
loader: 'weex-loader'
}]
}
],
},
plugins: plugins,
}; var exports = [webConfig, weexConfig]; module.exports = exports;

6.修改 webpack 开发环境文件

webpack.dev.js

const ip = require('quick-local-ip').getLocalIP4();
const configs = require('./webpack.config.js');
const webpack = require('webpack');
const pathTo = require('path');
const chalk = require('chalk');
let config = Array.isArray(configs) ? configs[0] : configs;
config.devServer = {
contentBase: pathTo.join(__dirname, ''),
compress: true,
// hot: true,
host: '0.0.0.0',
public: ip + ':8080/web',
// publicPath: '/dist/',
};
// configs.plugins.push(new webpack.HotModuleReplacementPlugin());
console.log('server is running! Please open ' + chalk.green('http://' + ip + ':8080/web/index.html'));
module.exports = config;

7.提取 weex-ui 组件

项目名称 / index.js

/**
* weex-ui 常用组件
*/ import Utils from './packages/utils';
import WxcButton from './packages/wxc-button';
import WxcCell from './packages/wxc-cell';
import WxcCheckbox from './packages/wxc-checkbox';
import WxcCheckboxList from './packages/wxc-checkbox-list';
import WxcCountdown from './packages/wxc-countdown';
import WxcDialog from './packages/wxc-dialog';
import WxcEpSlider from './packages/wxc-ep-slider';
import WxcPanItem from './packages/wxc-pan-item';
import WxcGridSelect from './packages/wxc-grid-select';
import WxcIndexlist from './packages/wxc-indexlist';
import WxcLightbox from './packages/wxc-lightbox';
import WxcLoading from './packages/wxc-loading';
import WxcPartLoading from './packages/wxc-part-loading';
import WxcMask from './packages/wxc-mask';
import WxcMinibar from './packages/wxc-minibar';
import WxcLotteryRain from './packages/wxc-lottery-rain';
import WxcNoticebar from './packages/wxc-noticebar';
import WxcOverlay from './packages/wxc-overlay';
import WxcPageCalendar from './packages/wxc-page-calendar';
import WxcPopup from './packages/wxc-popup';
import WxcProgress from './packages/wxc-progress';
import WxcRadio from './packages/wxc-radio';
import WxcResult from './packages/wxc-result';
import WxcRichText from './packages/wxc-rich-text';
import WxcSpecialRichText from './packages/wxc-special-rich-text';
import WxcSearchbar from './packages/wxc-searchbar';
import WxcSimpleFlow from './packages/wxc-simple-flow';
import WxcSlideNav from './packages/wxc-slide-nav';
import WxcSliderBar from './packages/wxc-slider-bar';
import WxcStepper from './packages/wxc-stepper';
import WxcTabPage from './packages/wxc-tab-page';
import WxcTabBar from './packages/wxc-tab-bar';
import WxcTag from './packages/wxc-tag'; export {
Utils,
WxcButton,
WxcCell,
WxcCheckbox,
WxcCheckboxList,
WxcCountdown,
WxcDialog,
WxcEpSlider,
WxcPanItem,
WxcGridSelect,
WxcIndexlist,
WxcLightbox,
WxcLoading,
WxcPartLoading,
WxcMask,
WxcMinibar,
WxcLotteryRain,
WxcNoticebar,
WxcOverlay,
WxcPageCalendar,
WxcPopup,
WxcProgress,
WxcRadio,
WxcResult,
WxcRichText,
WxcSpecialRichText,
WxcSearchbar,
WxcSimpleFlow,
WxcSlideNav,
WxcSliderBar,
WxcStepper,
WxcTabPage,
WxcTabBar,
WxcTag
};

.

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. UVa 11987 并查集 Almost Union-Find

    原文戳这 与以往的并查集不同,这次需要一个删除操作.如果是叶子节点还好,直接修改父亲指针就好. 但是如果要是移动根节点,指向它的所有子节点也会跟着变化. 所以要增加一个永远不会被修改的虚拟根节点,这样 ...

  2. 【SaltStack】SaltStack研究心得

    基础篇 ------------------------------------------------------------------------------------------------ ...

  3. Oracle中Restore和Recovery的区别

    一.参考解释一 在Oracle的备份与恢复的知识点中,经常会出现Restore 和 Recovery两个词. 由于这两个词在字典中的解释很接近,困扰了我很久.直到我在Oracle的官方文档中看到了以下 ...

  4. 00030_ArrayList集合

    1.数组可以保存多个元素,但在某些情况下无法确定到底要保存多少个元素,此时数组将不再适用,因为数组的长度不可变 2.JDK中提供了一系列特殊的类,这些类可以存储任意类型的元素,并且长度可变,统称为集合 ...

  5. luogu2483 【模板】k短路([SDOI2010]魔法猪学院)

    模板题 #include <iostream> #include <cstring> #include <cstdio> #include <queue> ...

  6. How To Configure VMware fencing using fence

    本文主要简单介绍一下如何在RHEL 7 Pacemaker中配置一个fence_vmware_soap类型的STONITH设备(仅供测试学习). STONITH是Shoot-The-Other-Nod ...

  7. 使用systemctl命令管理服务mysql

    启动mysql systemctl start mysqld.service 停止mysql systemctl stop mysqld.service 重启mysql systemctl resta ...

  8. 【LeetCode】Combination Sum II(组合总和 II)

    这道题是LeetCode里的第40道题. 题目要求: 给定一个数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合. can ...

  9. Python之转换py文件为无需依赖python环境的exe文件的方法

    在日常工作中,使用python脚本开发快速敏捷,但是其代码是可见的,而且充分的依赖python开发环境.为了达到保护我们源码的目的,或者不依赖python开发环境使用python脚本,将其转换成可以直 ...

  10. 【Luogu】P3116会议时间(拓扑排序,DP)

    题目链接 本题使用拓扑排序来规划DP顺序.设s[i][j]表示i步是否能走到j这个点,e[i][j]表示i步是否能走到j这个点——用第二条路径.因为要满足无后效性和正确性,只有第i个点已经全部更新完毕 ...