作者:doliangzhe | 来源:互联网 | 2023-10-16 13:15
vux2模板fork自webpack模板,基本和官方同步。1、默认为webpack2模板npminstallvue-cli-g如果还没安装vueinitairyla
vux2 模板 fork 自 webpack 模板,基本和官方同步。
1、默认为 webpack2 模板
npm install vue-cli -g // 如果还没安装
vue init airyland/vux2 projectPath // 创建名为 my-project 的模板
cd projectPath // 进入项目
npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm install // 开始安装
npm run dev 或者 yarn dev // 运行项目
2、安装 vux,vux-loader
npm install vux --save
npm install vux-loader --save-dev
3、安装less-loader (这个是用以正确编译less源码,否则会出现 ’ Cannot GET / ')
npm install less less-loader --save-dev
4、安装yaml-loader (以正确进行语言文件读取, 我没安装似乎也没报错)
npm install yaml-loader --save-dev
5、vux2必须配合vux-loader使用, 请在build/webpack.base.conf.js里参照如下代码进行配置:
const vuxLoader = require('vux-loader')
const webpackConfig = originalConfig module.exports = vuxLoader.merge(webpackConfig, {plugins: ['vux-ui']
})
6、resolve加上.less
7、在build/webpack.base.conf.js全部文件如下
'use strict'
const path = require('path')
const utils = require('./utils')
const config = require('../config')
const vueLoaderConfig = require('./vue-loader.conf')function resolve (dir) {return path.join(__dirname, '..', dir)
}const createLintingRule = () => ({
})const webpackConfig = {context: path.resolve(__dirname, '../'),entry: {app: './src/main.js'},output: {path: config.build.assetsRoot,filename: '[name].js',publicPath: process.env.NODE_ENV === 'production'? config.build.assetsPublicPath: config.dev.assetsPublicPath},resolve: {extensions: ['.js', '.vue', '.json','.less'],alias: {'vue$': 'vue/dist/vue.esm.js','@': resolve('src'),}},module: {rules: [...(config.dev.useEslint ? [createLintingRule()] : []),{test: /\.vue$/,loader: 'vue-loader',options: vueLoaderConfig},{test: /\.js$/,loader: 'babel-loader',include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]},{test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,loader: 'url-loader',options: {limit: 10000,name: utils.assetsPath('img/[name].[hash:7].[ext]')}},{test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,loader: 'url-loader',options: {limit: 10000,name: utils.assetsPath('media/[name].[hash:7].[ext]')}},{test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,loader: 'url-loader',options: {limit: 10000,name: utils.assetsPath('fonts/[name].[hash:7].[ext]')}},{test: /\.less$/,loader:"style-loader!css-loader!less-loader",}]},node: {setImmediate: false,dgram: 'empty',fs: 'empty',net: 'empty',tls: 'empty',child_process: 'empty'}}
module.exports = vuxLoader.merge(webpackConfig, {plugins: ['vux-ui']
})
▼更多相关技术干货,请扫描关注公众号▼