Commit 224d5a27 authored by 尚斌杰's avatar 尚斌杰

增加全局依赖路径配置

parent 91466f9a
......@@ -7,4 +7,14 @@ vue add ts-multi-pages
npm run add [page]
### 构建页面
npm run build [page1+page2] or npm run build [page1]
\ No newline at end of file
npm run build [page1+page2] or npm run build [page1]
### 使用DllReferencePlugin, 需要配置提取dll js的路径
```js
//package.json
{
...,
"commonPath": "../common.js",
...,
}
```
......@@ -17,7 +17,14 @@ const buildModes = {
if(!fs.existsSync(path.resolve('./src/pages'))){
fs.mkdirSync(path.resolve('./src/pages'))
}
const allPages = fs.readdirSync(path.resolve('./src/pages/')).filter(page=>(page!=='.DS_Store' && page !=='common'))
const allPages = []
const dirs = fs.readdirSync(path.resolve('./src/pages/')).filter(page=>(page!=='.DS_Store' && page !=='common'))
for (let index = 0; index < dirs.length; index++) {
const dirName = dirs[index];
if(fs.existsSync(`${process.cwd()}/src/pages/${dirName}/index.ts`) && dirName !== 'common'){
allPages.push(dirName)
}
}
const modifyConfig = (config, fn) => {
if (Array.isArray(config)) {
config.forEach(c => fn(c))
......@@ -26,6 +33,9 @@ const modifyConfig = (config, fn) => {
}
}
const _packageJson = fs.readFileSync(`${process.cwd()}/package.json`)
const { commonPath } = JSON.parse(_packageJson)
module.exports = (api, options) => {
api.registerCommand('build', {
description: 'build for production',
......@@ -52,15 +62,8 @@ module.exports = (api, options) => {
}
if(!args._[0]){
const stat = fs.statSync(`${process.cwd()}/src/pages`)
if(stat.isDirectory()){
const dirs = fs.readdirSync(`${process.cwd()}/src/pages`)
const commonIndex = dirs.indexOf('common')
if(commonIndex>=0){
dirs.splice(commonIndex,1)
}
args._[0] = dirs.join('+')
if(allPages){
args._[0] = allPages.join('+')
} else {
console.log(chalk.red('找不到需要打包的目录pages'))
return
......@@ -205,9 +208,10 @@ async function build (args, api, options) {
webpackConfig.output.path = targetDir
for(let item of webpackConfig.plugins) {
if (item.options && item.options.template) {
item.options.template= pagePath + '/index.html'
item.options.template = pagePath + '/index.html'
item.options.header = headerTpl
item.options.footer = footerTpl
item.options.common = (commonPath && process.env.NODE_ENV === 'production')?`<script src="${commonPath}"></script>`:''
}
}
for (let item of webpackConfig.module.rules) {
......
......@@ -8,6 +8,7 @@
<script>
;(function(l,f){var c=l.documentElement,h="orientationchange" in f?"orientationchange":"resize",g=function(){var i=c.clientWidth;if(!i){return}c.style.fontSize=(100*(i/375))/2+"px"};if(!l.addEventListener){return}var b=function(){var i=l.documentElement.clientWidth;f.innerHeight;320>=i&&(i=320),i>=750&&(i=750);var m=((i/375)*100)/2;l.documentElement.style.fontSize=m+"px"};b();f.addEventListener("resize",b);f.addEventListener(h,g,false);f.addEventListener("resize",b);l.addEventListener("DOMContentLoaded",g,false);console.log("屏幕dpr:",devicePixelRatio);var d=null;var j=l.getElementsByTagName("meta");for(var e=0;e<j.length;e++){if(j[e].getAttribute("name")==="viewport"){d=j[e];break}}var a="width=device-width,initial-scale=1.0, maximum-scale=1.0, user-scalable=0";if(/(iPhone|iPod|iPad)/i.test(f.navigator.userAgent)){var k=parseInt(f.navigator.userAgent.match(/OS (\d+)_(\d+)_?(\d+)? like Mac OS X/i)[1]);if(k>=11){a+=", viewport-fit=cover"}}d.setAttribute("content",a)})(document,window);
</script>
<%= htmlWebpackPlugin.options.common %>
<%= htmlWebpackPlugin.options.header %>
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title>{{title}}</title>
......
{
"name": "vue-cli-plugin-ts-multi-pages",
"version": "1.1.9",
"version": "1.1.10",
"description": "vue-cli3多页开发插件TS版",
"main": "index.js",
"scripts": {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment