webpack打包单页面如何引用的js
程序员文章站
2022-04-10 10:12:52
目录结构如下图所示:
webpack打包代码如下:
var webpack = require('webpack');
var fs = require(...
目录结构如下图所示:
webpack打包代码如下:
var webpack = require('webpack'); var fs = require('fs'); var path = require('path'); var fse = require('fs-extra'); const debug = process.env.node_env !== 'production'; function entries(jspath) { var dirnames = fs.readdirsync(jspath); var entries = {}, entry; for (var i = 0; i < dirnames.length; i++) { var dirname, basename; var jslist = []; dirname = dirnames[i]; var files = fs.readdirsync(jspath + '/' + dirname); for (var j = 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; } return entries; } var option = { entry: entries(__dirname + '/js/src'), output: { path: __dirname + '/dist/', filename: '[name].js' }, plugins: [ new webpack.optimize.uglifyjsplugin({ compress: { warnings: false } }) ] } var compiler = webpack(option); compiler.run(function() { fse.copy( __dirname + '/page/', __dirname + '/dist/'); console.log('success'); });
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
上一篇: JavaScript实现提交模式窗口后刷新父窗口数据的方法
下一篇: 关于使用js算总价的问题
推荐阅读