1 Star 0 Fork 0

李鑫松/vue_moer_page

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
vue.config.js 1.93 KB
一键复制 编辑 原始数据 按行查看 历史
李鑫松 提交于 2018-12-27 17:25 . 多页面Demo
const path = require('path');
const fs = require('fs');
const config = {
entry: 'main.js',
html: 'index.html',
pagesRoot: path.resolve(__dirname, 'src/pages')
};
const genRoutes = () => {
const allRoutes = [];
const findAllRoutes = (source, routes) => {
const files = fs.readdirSync(source);
files.forEach(filename => {
const fullname = path.join(source, filename);
const stats = fs.statSync(fullname);
if (!stats.isDirectory()) return;
if (fs.existsSync(`${fullname}/${config.html}`)) {
routes.push(fullname);
} else {
findAllRoutes(fullname, routes);
}
});
};
findAllRoutes(config.pagesRoot, allRoutes);
return allRoutes;
};
const genPages = () => {
const pages = {};
genRoutes().forEach(route => {
const filename = route.slice(config.pagesRoot.length + 1);
pages[filename] = {
entry: `${route}/${config.entry}`,
template: `${route}/${config.html}`,
filename:
filename === 'index' ? config.html : `${filename}/${config.html}`
};
});
return pages;
};
const pages = genPages();
module.exports = {
productionSourceMap: false,
pages,
chainWebpack: config => {
// remove prefetch, use import(/* webpackPrefetch: true */ './someAsyncComponent.vue')
Object.keys(pages).forEach(entryName => {
config.plugins.delete(`prefetch-${entryName}`);
});
if (process.env.NODE_ENV === 'production') {
config.plugin('extract-css').tap(() => [
{
filename: '[name]/css/[name].[contenthash:8].css',
chunkFilename: '[name]/css/[name].[contenthash:8].css'
}
]);
}
},
configureWebpack: config => {
if (process.env.NODE_ENV === 'production') {
config.output = {
path: path.join(__dirname, './dist'),
filename: '[name]/js/[name].[contenthash:8].js',
publicPath: '/',
chunkFilename: '[name]/js/[name].[contenthash:8].js'
};
}
}
};
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lixinsong/vue_moer_page.git
git@gitee.com:lixinsong/vue_moer_page.git
lixinsong
vue_moer_page
vue_moer_page
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385