最新下载
热门教程
- 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'); }); |
相关文章
- 《燕云十六声》配置要求介绍 12-25
- 《燕云十六声》搬砖介绍 12-25
- 时空中的绘旅人天宇之间怎么玩 绘旅人天宇之间活动玩法介绍 12-25
- QQ2024年度报告怎么看 2024qq年度报告玩法介绍 12-25
- 归龙潮珠砂什么时候up 归龙潮红缘绮梦卡池介绍 12-25
- 王者荣耀S38赛季有什么更新 12-25