Authored by hongyong.zhao

修改webpack配置

@@ -9,6 +9,17 @@ @@ -9,6 +9,17 @@
9 9
10 <body> 10 <body>
11 <div id="app"></div> 11 <div id="app"></div>
  12 + <% for (var i=0; i<htmlWebpackPlugin.options.externalscripts.length; i++) {
  13 + var script = htmlWebpackPlugin.options.externalscripts[i];
  14 + %>
  15 + <script type="text/javascript" src="<%= script %>"></script>
  16 + <% } %>
  17 +
  18 + <% if (htmlWebpackPlugin.options.filename === 'coupon.html') { %>
  19 +
  20 + <script type="text/javascript" src="<%= htmlWebpackPlugin.options.xlsScript%>"> </script>
  21 + <%} %>
  22 +
12 </body> 23 </body>
13 24
14 -</html>  
  25 +</html>
@@ -86,7 +86,7 @@ @@ -86,7 +86,7 @@
86 <script> 86 <script>
87 import Api from 'api/api'; 87 import Api from 'api/api';
88 import dayjs from 'dayjs'; 88 import dayjs from 'dayjs';
89 -import xlsx from 'xlsx'; 89 +import XLSX from 'xlsx';
90 90
91 const api = new Api(); 91 const api = new Api();
92 const forbidenTypeMap = { 92 const forbidenTypeMap = {
@@ -316,7 +316,7 @@ export default { @@ -316,7 +316,7 @@ export default {
316 }, 316 },
317 onBeforeUpload(file) { 317 onBeforeUpload(file) {
318 const fileExt = file.name.split('.').pop().toLocaleLowerCase(); 318 const fileExt = file.name.split('.').pop().toLocaleLowerCase();
319 - if (fileExt !== 'xlsx') { 319 + if (fileExt !== 'XLSX') {
320 this.$Message.warning('文件格式错误'); 320 this.$Message.warning('文件格式错误');
321 return false; 321 return false;
322 } 322 }
@@ -340,28 +340,28 @@ export default { @@ -340,28 +340,28 @@ export default {
340 this.uploadTxt = ''; 340 this.uploadTxt = '';
341 try { 341 try {
342 const data = e.target.result; 342 const data = e.target.result;
343 - const workbook = xlsx.read(data, { type: 'array' }); 343 + const workbook = XLSX.read(data, { type: 'array' });
344 const firstSheetName = workbook.SheetNames[0]; 344 const firstSheetName = workbook.SheetNames[0];
345 const worksheet = workbook.Sheets[firstSheetName]; 345 const worksheet = workbook.Sheets[firstSheetName];
346 - const results = xlsx.utils.sheet_to_json(worksheet); 346 + const results = XLSX.utils.sheet_to_json(worksheet);
347 347
348 this.formData.productLimitValue = results.map(r => r['商品编码']).filter(r => r).join(','); 348 this.formData.productLimitValue = results.map(r => r['商品编码']).filter(r => r).join(',');
349 349
350 } catch (error) { 350 } catch (error) {
351 this.uploadTxt = '文件解析失败,请按照格式上传'; 351 this.uploadTxt = '文件解析失败,请按照格式上传';
352 } 352 }
353 - 353 +
354 354
355 }; 355 };
356 return false; 356 return false;
357 }, 357 },
358 onExample() { 358 onExample() {
359 - const wb = xlsx.utils.book_new();  
360 - const ws = xlsx.utils.json_to_sheet([{ 359 + const wb = XLSX.utils.book_new();
  360 + const ws = XLSX.utils.json_to_sheet([{
361 '商品编码': '123456' 361 '商品编码': '123456'
362 }]); 362 }]);
363 - xlsx.utils.book_append_sheet(wb, ws, '优惠券适用范围示例');  
364 - xlsx.writeFile(wb, '优惠券适用范围示例.xlsx'); 363 + XLSX.utils.book_append_sheet(wb, ws, '优惠券适用范围示例');
  364 + XLSX.writeFile(wb, '优惠券适用范围示例.xlsx');
365 } 365 }
366 } 366 }
367 }; 367 };
@@ -13,7 +13,9 @@ fs @@ -13,7 +13,9 @@ fs
13 filename: `${file}.html`, 13 filename: `${file}.html`,
14 template: './src/template/index.ejs', 14 template: './src/template/index.ejs',
15 inject: true, 15 inject: true,
16 - chunks: ['vendors', file] 16 + chunks: ['vendors', file],
  17 + externalscripts: ["https://cdn.yoho.cn/20190712/vue.min.js", 'https://cdn.yoho.cn/20190712/iview.min.js'],
  18 + xlsScript:'https://cdn.yoho.cn/20190712/xlsx.full.min.js',
17 })); 19 }));
18 }); 20 });
19 21
@@ -22,6 +24,11 @@ module.exports = { @@ -22,6 +24,11 @@ module.exports = {
22 output: { 24 output: {
23 path: path.join(__dirname, './dist') 25 path: path.join(__dirname, './dist')
24 }, 26 },
  27 + externals: {
  28 + vue: 'Vue',
  29 + iview: 'iview',
  30 + xlsx: 'XLSX'
  31 + },
25 module: { 32 module: {
26 rules: [{ 33 rules: [{
27 test: /.vue$/, 34 test: /.vue$/,
@@ -102,11 +109,11 @@ module.exports = { @@ -102,11 +109,11 @@ module.exports = {
102 'node_modules' 109 'node_modules'
103 ], 110 ],
104 alias: { 111 alias: {
105 - 'vue': 'vue/dist/vue.esm.js',  
106 '@': path.join(process.cwd(), 'src'), 112 '@': path.join(process.cwd(), 'src'),
107 'components': path.join(process.cwd(), 'src/components'), 113 'components': path.join(process.cwd(), 'src/components'),
108 'assets': path.join(process.cwd(), 'src/assets') 114 'assets': path.join(process.cwd(), 'src/assets')
109 } 115 }
110 }, 116 },
111 - plugins: plugins  
112 -};  
  117 + plugins: [...plugins]
  118 +
  119 +};