Skip to content

Commit bcd8077

Browse files
committed
fix easyfiy env
1 parent db6dd1b commit bcd8077

File tree

7 files changed

+84
-37
lines changed

7 files changed

+84
-37
lines changed

build/deploy/index.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const AWS = require('aws-sdk');
4+
const s3Option = require('./s3Options')('xjp');
5+
const s3 = new AWS.S3(s3Option);
6+
const {
7+
project
8+
} = require('../lib/project');
9+
// 本来打算用aws-sdk的putObject方法来上传文件到s3,但是发现性能一般,要用fs遍历每个层级的文件夹,先放着
10+
// const projectDistDir = path.resolve(__dirname, '../../dist/' + project);
11+
// fs.readdirSync(projectDistDir).map(filename => {
12+
13+
// console.log(filename);
14+
// })

build/deploy/s3Options.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//https://docs.aws.amazon.com/zh_cn/general/latest/gr/rande.html
2+
/**
3+
* 常用的region
4+
'us-east-1' // 美国东部 弗吉尼亚
5+
'ap-south-1' // 亚太地区 孟买
6+
'ap-southeast-1' // 亚太地区 新加坡
7+
*/
8+
9+
let options = {
10+
apiVersion: '2006-03-01',
11+
endpoint: 'https://s3.amazonaws.com'
12+
}
13+
14+
module.exports = function (region) {
15+
let re = null;
16+
switch (region) {
17+
case 'fjny':
18+
re = 'us-east-1'
19+
case 'mm':
20+
re = 'us-south-1'
21+
case 'xjp':
22+
re = 'us-southeast-1'
23+
}
24+
return {
25+
...options,
26+
region: re
27+
}
28+
}

build/lib/multipages.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ const HtmlWebpackPlugin = require("html-webpack-plugin");
44
const HtmlWebpackIncludeAssetsPlugin = require('html-webpack-include-assets-plugin');
55
const {
66
project,
7-
env
7+
env,
8+
multi
89
} = require('./project');
910
const config = require('../config/index');
1011
let reg = /\.\S+$/;
@@ -16,12 +17,12 @@ let VUE = config.vue;
1617
let minify = undefined;
1718
// console.log(config);
1819
if (env === 'prod') {
19-
minify = {
20-
removeComments: true,
21-
collapseWhitespace: true,
22-
removeAttributeQuotes: true,
23-
chunksSortMode: 'dependency'
24-
};
20+
// minify = {
21+
// removeComments: true,
22+
// collapseWhitespace: true,
23+
// removeAttributeQuotes: true,
24+
// chunksSortMode: 'dependency'
25+
// };
2526
projectDistDir = path.resolve(__dirname, '../../dist/' + project) + '/'; //项目多页面的pages目录
2627
}
2728
fs.readdirSync(pagesDir)
@@ -41,6 +42,7 @@ const extraEntry = pagesPath;
4142
// // 生成HtmlWebpackPlugin
4243
let extraHtmlWebpackPlugins = [];
4344
for (let i in pagesPath) {
45+
4446
extraHtmlWebpackPlugins.push(
4547
new HtmlWebpackPlugin({
4648
filename: projectDistDir + i + ".html",
@@ -49,7 +51,7 @@ for (let i in pagesPath) {
4951
minify: env === 'prod' ? minify : {}
5052
}),
5153
new HtmlWebpackIncludeAssetsPlugin({
52-
assets: env === 'prod' ? ['vendor.dll.js'] : ['static/js/vendor.dll.js'],
54+
assets: env === 'prod' ? ['../static/js/vendor.dll.js'] : ['static/js/vendor.dll.js'],
5355
append: false
5456
})
5557
);

build/webpack/webpack.base.conf.js

+10-11
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,19 @@ let distProjectDir = path.resolve(__dirname, '../../dist/' + project);
1818
let optimization = {};
1919
if (config.vendor && config.vendor.length === 0) {
2020
optimization = {
21-
splitChunks: {
22-
cacheGroups: {
23-
commons: {
24-
test: /[\\/]node_modules[\\/]/,
25-
name: "vendor",
26-
chunks: "all"
27-
}
28-
}
29-
}
21+
// splitChunks: {
22+
// cacheGroups: {
23+
// commons: {
24+
// test: /[\\/]node_modules[\\/]/,
25+
// name: "vendor",
26+
// chunks: "all"
27+
// }
28+
// }
29+
// }
3030
};
3131
}
3232

3333
const baseConfig = {
34-
mode: process.env.NODE_ENV,
3534
entry: {
3635
index: projectDir + '/index.js',
3736
...extraEntry
@@ -65,7 +64,7 @@ const baseConfig = {
6564
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
6665
loader: "url-loader",
6766
options: {
68-
limit: 1000,
67+
limit: 5000,
6968
// name: env === 'prod' ? "static/images/[name].[hash:5].[ext]" : "static/images/[name].[hash:5].[ext]"
7069
name: "static/images/[name].[hash:5].[ext]"
7170
}

build/webpack/webpack.dev.conf.js

+10-11
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,12 @@ let projectDir = path.resolve('./src/' + project);
2525
let dllRef = [];
2626

2727
if (config.vendor && config.vendor.length > 0) {
28-
try {
29-
dllRef = [
30-
new webpack.DllReferencePlugin({
31-
context: __dirname,
32-
manifest: require(projectDir + '/static/manifest.json')
33-
})
34-
]
35-
} catch (error) {
36-
throw new Error('There is no manifest.json, need to run <npm run dll xx>')
37-
}
38-
28+
dllRef = [
29+
new webpack.DllReferencePlugin({
30+
context: __dirname,
31+
manifest: require(projectDir + '/static/manifest.json')
32+
})
33+
]
3934
}
4035

4136

@@ -100,6 +95,10 @@ const webpackConfig = merge(baseConfig, {
10095
from: projectDir + '/static/js/',
10196
to: 'static/js/',
10297
ignore: ['.*']
98+
},{
99+
from: projectDir + '/static/images/',
100+
to: 'static/images/',
101+
ignore: ['.*']
103102
}]),
104103
// new CopyWebpackPlugin([{
105104
// from: projectDir + '/assets',

build/webpack/webpack.dll.conf.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if (conf.vendor.length === 0) {
1414
throw new Error('Before dll bundle, you must set the key "vendeor" in config.js')
1515
}
1616
const dllConfig = {
17-
mode: process.env.NODE_ENV,
17+
mode: env === 'prod' ? 'production' : 'development',
1818
entry: {
1919
'vendor': [...conf.vendor]
2020
},
@@ -32,12 +32,12 @@ const dllConfig = {
3232
}),
3333
//创建dll的时候给html添加相应的代码
3434

35-
new HtmlWebpackPlugin({
36-
filename: projectDir + "/index.html",
37-
template: projectDir + "/index.html",
38-
chunks: ['vendor'],
39-
inject: 'body'
40-
}),
35+
// new HtmlWebpackPlugin({
36+
// filename: projectDir + "/index.html",
37+
// template: projectDir + "/index.html",
38+
// chunks: ['vendor'],
39+
// inject: 'body'
40+
// }),
4141
// new HtmlWebpackIncludeAssetsPlugin({
4242
// assets: env === 'prod' ? ['vendor.dll.js'] : ['/static/js/vendor.dll.js'],
4343
// append: false

build/webpack/webpack.prod.conf.js

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const {
1919
} = require('../lib/project');
2020
//多页面情况
2121
let extraHtmlWebpackPlugins = [];
22+
console.log(multi)
2223
if (config.multi || multi === 'true') {
2324
const multiBuilder = require("../lib/multipages");
2425
extraHtmlWebpackPlugins = multiBuilder.extraHtmlWebpackPlugins;
@@ -134,6 +135,10 @@ const webpackConfig = merge(baseConfig, {
134135
from: projectDir + '/static/js/',
135136
to: distProjectDir + '/static/js/',
136137
ignore: ['.*']
138+
},{
139+
from: projectDir + '/static/images/',
140+
to: 'static/images/',
141+
ignore: ['.*']
137142
}]),
138143
...dllRef,
139144
...extraGzip

0 commit comments

Comments
 (0)