最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
webpack打包单页面如何引用的js
时间:2022-06-29 01:30:45 编辑:袖梨 来源:一聚教程网
目录结构如下图所示:
webpack打包代码如下:
代码如下 | 复制代码 |
varwebpack = require('webpack'); varfs = require('fs'); varpath = require('path'); varfse = require('fs-extra');
const debug = process.env.NODE_ENV !=='production'
functionentries(jsPath) { vardirnames = fs.readdirSync(jsPath);
varentries = {}, entry;
for(vari = 0; i < dirnames.length; i++) { vardirname, basename; varjsList = []; dirname = dirnames[i]; varfiles = fs.readdirSync(jsPath +'/'+ dirname); for(varj = 0; j < files.length; j++) { entry = files[j];
basename = path.basename(entry,'.js'); jsList.push(path.join(jsPath, dirname, entry)); } entries[path.join(dirname,'app')] = jsList; }
returnentries; }
varoption = { entry: entries(__dirname +'/js/src'), output: { path: __dirname +'/dist/', filename:'[name].js' }, plugins: [ newwebpack.optimize.UglifyJsPlugin({ compress: { warnings:false } }) ] } varcompiler = webpack(option); compiler.run(function() { fse.copy( __dirname +'/page/', __dirname +'/dist/'); console.log('success'); }); |
相关文章
- 《绝区零》伊芙琳培养材料汇总 01-24
- 《无限暖暖》1.2春节兑换码一览 01-24
- 《网上国网》查询阶梯档位方法 01-24
- 《蛋仔派对》神游贺岁盲盒获取方法 01-24
- 《炉石传说》星际联动盗贼卡组玩法介绍 01-24
- 皮革珊瑚属于珊瑚中的 01-24