欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue 多入口文件搭建 vue多頁面搭建的實例講解

 更新時間:2018年03月12日 16:49:45   投稿:jingxian  
下面小編就為大家分享一篇vue 多入口文件搭建 vue多頁面搭建的實例講解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

紅色為更改后的不同之處

vue 多入口文件搭建

在webpack.base.conf

中修改

var
path = require('path')
var
config = require('../config')
var
utils = require('./utils')
var
projectRoot = 
path.resolve(__dirname,'../')
var glob = require('glob');
var entries = getEntry('./src/module/*.js'); // 獲得入口js文件
module.exports = {
entry: entries,
output: {
path:config.build.assetsRoot,
publicPath:process.env.NODE_ENV
 ==='production' ? 
config.build.assetsPublicPath :config.dev.assetsPublicPath,
filename: '[name].js'
},
resolve: {
extensions: ['','.js',
'.vue'],
fallback: [path.join(__dirname,'../node_modules')],
alias: {
'src':path.resolve(__dirname,'../src'),
'assets':path.resolve(__dirname,'../src/assets'),
'components':path.resolve(__dirname,'../src/components')
}
},
resolveLoader: {
fallback: [path.join(__dirname,'../node_modules')]
},
module: {
loaders: [
{
test: /\.vue$/,
loader:'vue'
},
{
test: /\.js$/,
loader:'babel',
include:projectRoot,
exclude: /node_modules/
},
{
test: /\.json$/,
loader:'json'
},
{
test: /\.html$/,
loader:'vue-html'
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader:'url',
query: {
limit:10000,
name:utils.assetsPath('img/[name].[hash:7].[ext]')
}
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader:'url',
query: {
limit:10000,
name:utils.assetsPath('fonts/[name].[hash:7].[ext]')
}
}
]
},
vue: {
loaders:utils.cssLoaders()
}
}
function getEntry(globPath) {
var entries = {},
basename, tmp, pathname;
glob.sync(globPath).forEach(function (entry) {
basename = path.basename(entry, path.extname(entry));
console.log(1,basename);
tmp = entry.split('/').splice(-3);
console.log(2,tmp);
pathname = basename; // 正確輸出js和html的路徑
console.log(3,pathname);
entries[pathname] = entry;
console.log(4,entry);
});
console.log("base-entrys:");
console.log(5,entries);
return entries;
}

這樣一來的話,就在中細(xì)分,最后輸出html都在dist下。

這里的字符串操作也是和路徑的情況相匹配的,如果有需要進(jìn)行其他方式的設(shè)定,注意在這里修改路徑的識別。

vue多頁面搭建

原本的webpack.dev.conf中有一個插件的設(shè)置內(nèi)容

對這部分內(nèi)容進(jìn)行修改

var
config = require('../config')
var
webpack = require('webpack')
var
merge = require('webpack-merge')
var
utils = require('./utils')
var
baseWebpackConfig = 
require('./webpack.base.conf')
var
HtmlWebpackPlugin = 
require('html-webpack-plugin')
var path = require('path');
var glob = require('glob');
// add hot-reload related code to entry chunks
Object.keys(baseWebpackConfig.entry).forEach(function
 (name) {
baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name])
})
module.exports =merge(baseWebpackConfig,
 {
module: {
loaders:
utils.styleLoaders({
sourceMap: config.dev.cssSourceMap })
},
// eval-source-map is faster for development
devtool:
'#eval-source-map',
plugins: [
new
webpack.DefinePlugin({
'process.env':config.dev.env
}),
// https://github.com/glenjamin/webpack-hot-middleware#installation--usage
new
webpack.optimize.OccurenceOrderPlugin(),
new
webpack.HotModuleReplacementPlugin(),
new
webpack.NoErrorsPlugin(),
// https://github.com/ampedandwired/html-webpack-plugin
]
})
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 = basename; // 正確輸出js和html的路徑
entries[pathname] = entry;
});
console.log("dev-entrys:");
console.log(entries);
return entries;
}
var pages = getEntry('./pages/*.html');
console.log("dev pages----------------------");
for (var pathname in pages) {
console.log("filename:" + pathname + '.html');
console.log("template:" + pages[pathname]);
// 配置生成的html文件,定義路徑等
var conf = {
filename: pathname + '.html',
template: pages[pathname], // 模板路徑
minify: { //傳遞 html-minifier 選項給 minify 輸出
removeComments: true
},
inject: 'body', // js插入位置
chunks: [pathname, "vendor", "manifest"] // 每個html引用的js模塊,也可以在這里加上vendor等公用模塊
};
// 需要生成幾個html文件,就配置幾個HtmlWebpackPlugin對象
module.exports.plugins.push(new HtmlWebpackPlugin(conf));
}
----------------------------------------------
webpack.prod.conf配置
和webpack.dev.conf.js中做類似的處理,
先注釋掉原來的HtmlWebpackPlugin,然后在下面添加函數(shù),
通過迭代插入多個HtmlWebpackPlugin。
var
path =require('path')
var
config =require('../config')
var
utils =require('./utils')
var
webpack =require('webpack')
var
merge =require('webpack-merge')
var
baseWebpackConfig =require('./webpack.base.conf')
var
ExtractTextPlugin =require('extract-text-webpack-plugin')
var
HtmlWebpackPlugin =require('html-webpack-plugin')
var
env =process.env.NODE_ENV ==='testing'
?
require('../config/test.env')
:
config.build.env
var
glob =require('glob');
module.exports =merge(baseWebpackConfig,
 {
module: {
loaders:
utils.styleLoaders({sourceMap:
config.build.productionSourceMap,extract:
true })
},
devtool:
config.build.productionSourceMap ?'#source-map' :
false,
output: {
path:
config.build.assetsRoot,
filename:
utils.assetsPath('js/[name].[chunkhash].js'),
chunkFilename:
utils.assetsPath('js/[id].[chunkhash].js')
},
vue: {
loaders:
utils.cssLoaders({
sourceMap:
config.build.productionSourceMap,
extract:
true
})
},
plugins: [
// http://vuejs.github.io/vue-loader/workflow/production.html
new
webpack.DefinePlugin({
'process.env':env
}),
new
webpack.optimize.UglifyJsPlugin({
compress: {
warnings:
false
}
}),
new
webpack.optimize.OccurenceOrderPlugin(),
// extract css into its own file
new
ExtractTextPlugin(utils.assetsPath('css/[name].[contenthash].css')),
// generate dist index.html with correct asset hash for caching.
// you can customize output by editing /index.html
// see https://github.com/ampedandwired/html-webpack-plugin
// new HtmlWebpackPlugin({
// filename: process.env.NODE_ENV === 'testing'
// ? 'index.html'
// : config.build.index,
// template: 'index.html',
// inject: true,
// minify: {
// removeComments: true,
// collapseWhitespace: true,
// removeAttributeQuotes: true
// // more options:
// // https://github.com/kangax/html-minifier#options-quick-reference
// },
// // necessary to consistently work with multiple chunks via CommonsChunkPlugin
// chunksSortMode: 'dependency'
// }),
// 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
)
}
}),
// extract webpack runtime and module manifest to its own file in order to
// prevent vendor hash from being updated whenever app bundle is updated
new
webpack.optimize.CommonsChunkPlugin({
name:
'manifest',
chunks: ['vendor']
})
]
})
if (config.build.productionGzip)
 {
var
CompressionWebpackPlugin =require('compression-webpack-plugin')
webpackConfig.plugins.push(
new
CompressionWebpackPlugin({
asset:
'[path].gz[query]',
algorithm:
'gzip',
test:
newRegExp(
'\\.(' +
config.build.productionGzipExtensions.join('|')
 +
')$'
),
threshold:
10240,
minRatio:
0.8
})
)
}
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("prod-entrys:");
console.log(entries);
return entries;
}
var pages =getEntry('./pages/*.html');
console.log("prod pages-----");
for (varpathname inpages) {
 
 console.log("filename:"+pathname +'.html');
console.log("template:"+pages[pathname]);
// 配置生成的html文件,定義路徑等
var conf = {
filename: pathname +'.html',
template: pages[pathname],// 模板路徑
minify:{ //
removeComments:true,
collapseWhitespace: false
},
inject: true,// js插入位置
chunks: [pathname,"vendor", "manifest"]// 每個html引用的js模塊,也可以在這里加上vendor等公用模塊
};
// 需要生成幾個html文件,就配置幾個HtmlWebpackPlugin對象
module.exports.plugins.push(newHtmlWebpackPlugin(conf));
}

以上這篇vue 多入口文件搭建 vue多頁面搭建的實例講解就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue項目實現(xiàn)文件下載進(jìn)度條功能

    vue項目實現(xiàn)文件下載進(jìn)度條功能

    這篇文章主要介紹了vue項目實現(xiàn)文件下載進(jìn)度條功能,本文通過具體實現(xiàn)代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2021-09-09
  • vue實現(xiàn)省市區(qū)的級聯(lián)選擇

    vue實現(xiàn)省市區(qū)的級聯(lián)選擇

    這篇文章主要為大家詳細(xì)介紹了vue實現(xiàn)省市區(qū)的級聯(lián)選擇,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • vue下的elementui輪播圖自適應(yīng)高度問題

    vue下的elementui輪播圖自適應(yīng)高度問題

    這篇文章主要介紹了vue下的elementui輪播圖自適應(yīng)高度問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • Element Input輸入框的使用方法

    Element Input輸入框的使用方法

    這篇文章主要介紹了Element Input輸入框的使用方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07
  • Vue 瑩石攝像頭直播視頻實例代碼

    Vue 瑩石攝像頭直播視頻實例代碼

    本文通過實例代碼給大家介紹了vue 瑩石攝像頭直播視頻功能,文章還給大家提到了vue h5項目調(diào)用手機(jī)攝像頭錄像并上傳的功能,需要的朋友可以參考下
    2018-08-08
  • Vue全局事件總線和訂閱與發(fā)布使用案例分析講解

    Vue全局事件總線和訂閱與發(fā)布使用案例分析講解

    在?vue?里我們可以通過全局事件總線來實現(xiàn)任意組件之間通信,它的原理是給?Vue?的原型對象上面添加一個屬性。這樣的話我所有組件的都可以訪問到這個屬性,然后可以通過這個屬性來訪問其他組件給這個屬性上面綁定的一些方法,從而去傳遞數(shù)據(jù)
    2022-08-08
  • mint-ui在vue中的使用示例

    mint-ui在vue中的使用示例

    Mint UI 是 由餓了么前端團(tuán)隊推出的 一個基于 Vue.js 的移動端組件庫,這篇文章主要介紹了mint-ui在vue中的使用示例,這里整理了詳細(xì)的代碼,有需要的小伙伴可以參考下
    2018-04-04
  • 用vue設(shè)計一個日歷表

    用vue設(shè)計一個日歷表

    這篇文章主要介紹了如何用vue設(shè)計一個日歷表,幫助大家更好的理解和學(xué)習(xí)vue框架,感興趣的朋友可以了解下
    2020-12-12
  • vue背景圖片路徑問題及解決

    vue背景圖片路徑問題及解決

    這篇文章主要介紹了vue背景圖片路徑問題及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-07-07
  • 解決IOS端微信H5頁面軟鍵盤彈起后頁面下方留白的問題

    解決IOS端微信H5頁面軟鍵盤彈起后頁面下方留白的問題

    微信H5項目,ios端出現(xiàn)了軟鍵盤輸完隱藏后頁面不會回彈,下方會有一大塊留白。這篇文章主要介紹了決微信H5頁面軟鍵盤彈起后頁面下方留白的問題(iOS端) ,需要的朋友可以參考下
    2019-06-06

最新評論