-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
391 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,49 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1.0"> | ||
<link rel="icon" href="./icon.png"> | ||
<meta charset="utf-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width,initial-scale=1.0" /> | ||
<link rel="icon" href="./icon.png" /> | ||
|
||
<!-- 使用CDN加速的CSS文件,配置在vue.config.js下 --> | ||
<% for (var i in | ||
htmlWebpackPlugin.options.cdn&&htmlWebpackPlugin.options.cdn.css) { %> | ||
<link | ||
href="<%= htmlWebpackPlugin.options.cdn.css[i] %>" | ||
rel="preload" | ||
as="style" | ||
/> | ||
<link href="<%= htmlWebpackPlugin.options.cdn.css[i] %>" rel="stylesheet" /> | ||
<% } %> | ||
<!-- 使用CDN加速的JS文件,配置在vue.config.js下 --> | ||
<% for (var i in | ||
htmlWebpackPlugin.options.cdn&&htmlWebpackPlugin.options.cdn.js) { %> | ||
<link | ||
href="<%= htmlWebpackPlugin.options.cdn.js[i] %>" | ||
rel="preload" | ||
as="script" | ||
/> | ||
<% } %> | ||
|
||
<title>南邮电影协会</title> | ||
</head> | ||
<body> | ||
<noscript> | ||
<strong>We're sorry but awsome-ui doesn't work properly without JavaScript enabled. Please enable it to continue.</strong> | ||
<strong | ||
>We're sorry but awsome-ui doesn't work properly without JavaScript | ||
enabled. Please enable it to continue.</strong | ||
> | ||
<strong>请及时联系开发者.QQ:474504964</strong> | ||
</noscript> | ||
<div id="app"></div> | ||
<!-- built files will be auto injected --> | ||
|
||
<!-- 使用CDN加速的JS文件,配置在vue.config.js下 --> | ||
<% for (var i in | ||
htmlWebpackPlugin.options.cdn&&htmlWebpackPlugin.options.cdn.js) { %> | ||
<script src="<%= htmlWebpackPlugin.options.cdn.js[i] %>"></script> | ||
<% } %> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,16 +2,99 @@ const path = require('path') | |
function resolve(dir) { | ||
return path.join(__dirname, './', dir) | ||
} | ||
//Analyzer | ||
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; | ||
|
||
//gzip | ||
const CompressionWebpackPlugin = require('compression-webpack-plugin') | ||
const productionGzip = true // 是否使用gzip | ||
const productionGzipExtensions = ['js', 'css'] // 需要gzip压缩的文件后缀 | ||
|
||
//去掉注释 | ||
const UglifyJsPlugin = require('uglifyjs-webpack-plugin') | ||
|
||
//cdn | ||
// cdn预加载使用 | ||
const externals = { | ||
'vue': 'Vue', | ||
'vue-router': 'VueRouter', | ||
'vuex': 'Vuex', | ||
'axios': 'axios', | ||
} | ||
|
||
const cdn = { | ||
// 开发环境 | ||
dev: { | ||
css: [ | ||
|
||
], | ||
js: [ | ||
|
||
] | ||
}, | ||
// 生产环境 | ||
build: { | ||
css: [ | ||
|
||
], | ||
js: [ | ||
'https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.min.js', | ||
'https://cdn.jsdelivr.net/npm/[email protected]/dist/vue-router.min.js', | ||
'https://cdn.jsdelivr.net/npm/[email protected]/dist/vuex.min.js', | ||
'https://cdn.jsdelivr.net/npm/[email protected]/dist/axios.min.js', | ||
] | ||
} | ||
} | ||
|
||
module.exports = { | ||
publicPath: './', // 默认'/',部署应用包时的基本 URL | ||
outputDir: 'dist', | ||
assetsDir: '', // 相对于outputDir的静态资源(js、css、img、fonts)目录 | ||
runtimeCompiler: true, // 是否使用包含运行时编译器的 Vue 构建版本 | ||
productionSourceMap: false, // 生产环境的 source map | ||
configureWebpack: config => { | ||
configureWebpack: config => { //简单配置 | ||
const myConfig = {} | ||
if (process.env.NODE_ENV === 'production') { | ||
// 1. 生产环境npm包转CDN | ||
myConfig.externals = externals | ||
|
||
// gzip | ||
myConfig.plugins = [] | ||
// 2. 构建时开启gzip,降低服务器压缩对CPU资源的占用,服务器也要相应开启gzip | ||
productionGzip && myConfig.plugins.push( | ||
new CompressionWebpackPlugin({ | ||
algorithm: 'gzip', | ||
test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'), | ||
threshold: 10240, | ||
minRatio: 0.8 | ||
}) | ||
) | ||
|
||
// 去掉注释 | ||
myConfig.plugins.push( | ||
new UglifyJsPlugin({ | ||
uglifyOptions: { | ||
output: { | ||
comments: false, // 去掉注释 | ||
}, | ||
compress: { | ||
warnings: false, | ||
drop_console: true, | ||
drop_debugger: false, | ||
pure_funcs: ['console.log']//移除console | ||
} | ||
} | ||
}) | ||
) | ||
|
||
//analyzer | ||
myConfig.plugins.push( | ||
new BundleAnalyzerPlugin() | ||
) | ||
} | ||
return myConfig | ||
}, | ||
chainWebpack: config => { | ||
chainWebpack: config => { //高级配置 | ||
config.resolve.alias | ||
.set('@', resolve('src')) | ||
.set('_c', resolve('src/components/')) | ||
|
@@ -30,6 +113,18 @@ module.exports = { | |
webp: { quality: 75 } | ||
}) */ | ||
|
||
// 使用cdn | ||
config.plugin('html').tap(args => { | ||
if (process.env.NODE_ENV === 'production') { | ||
args[0].cdn = cdn.build | ||
} | ||
if (process.env.NODE_ENV === 'development') { | ||
args[0].cdn = cdn.dev | ||
} | ||
return args | ||
}) | ||
|
||
|
||
// svg rule loader | ||
const svgRule = config.module.rule('svg') // 找到svg-loader | ||
svgRule.uses.clear() // 清除已有的loader, 如果不这样做会添加在此loader之后 | ||
|
Oops, something went wrong.