参考网站:

  https://www.npmjs.com/package/babel-loader

  https://www.npmjs.com/package/gulp

  https://www.npmjs.com/package/gulp-webpack

新建个文件夹

安装gulp

安装gulp-webpack

创建gulpfile文件

并写入

 /**
* Created by Administrator on 2016/11/16.
*/
const gulp = require("gulp");
const webpack = require("gulp-webpack"); gulp.task("copy_html", function () {
gulp.src("src/*.html").pipe(gulp.dest("build"));
}); gulp.task("copy_package", function () {
gulp.src("src/package.json").pipe(gulp.dest("build"));
}); gulp.task("com_js", function () {
gulp.src("src/index.js").pipe(webpack({
output: {
filename: "index.js"
},
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel', // 'babel-loader' is also a valid name to reference
query: {
presets: ['es2017']
}
}
]
},
externals: {
electron: "require('electron')",
path: "require('path')",
url: "require('url')"
}
})).pipe(gulp.dest("build"));
}); gulp.task("copy_main", function () {
gulp.src("main.js").pipe(gulp.dest("build"));
}); gulp.task("default", ["copy_html", "copy_package", "com_js", "copy_main"]);

安装babel

现在看下目录结构

说明下,目的是把src文件和main.js文件通过编译放入build文件夹中

main.js代码

 /**
* Created by Administrator on 2016/11/16.
*/
const {app, BrowserWindow} = require('electron')
const path = require('path');
const url = require('url'); // Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win; function createWindow() {
// Create the browser window.
win = new BrowserWindow({width: 800, height: 600}) var filepath = path.join(__dirname, 'index.html'); console.log(filepath); // and load the index.html of the app.
win.loadURL(url.format({
pathname: path.join(__dirname,'index.html'),
protocol: 'file:',
slashes: true
})); // Open the DevTools.
win.webContents.openDevTools(); // Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null
})
} // This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow) // Quit when all windows are closed.
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
}); app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (win === null) {
createWindow()
}
});

src下的packjson文件内容:

 {
"scripts": {
"starts":"electron ."
},
"name": "application-name",
"version": "0.0.1",
"main": "main.js"
}

控制台中输入

  编译文件 gulp (在主文件下)

  打开build文件 cd build

  运行 electron .

结果

最后说明:gulp编译后有可能出现can not find module,解决方法,安装缺失的模块即可。。

gulp-webpack工程化实现electron的更多相关文章

  1. gulp & webpack整合

    为什么需要前端工程化? 前端工程化的意义在于让前端这个行业由野蛮时代进化为正规军时代,近年来很多相关的工具和概念诞生.好奇心日报在进行前端工程化的过程中,主要的挑战在于解决如下问题:✦ 如何管理多个项 ...

  2. nodejs+gulp+webpack基础知识

    nodejs+gulp+webpack基础知识 2019年08月22日 11:49:40 天府云创 阅读数 22   版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文 ...

  3. 做一个gulp+webpack+vue的单页应用开发架子

    1.目标 最近项目上的事情不多,根据我自己的开发习惯,决定开发一些简单的开发架子,方便以后事情多的时候直接套用.本文讲的一个gulp+webpack+vue的单页应用架子,想要达到的目的: 可以通过命 ...

  4. gulp + webpack + sass 学习

    笔记: new webpack.optimize.CommonsChunkPlugin 核心作用是抽离公共代码,chunks:['index.js','main.js'] 另一个作用就是单独生成一个j ...

  5. gulp+webpack+vue

    gulp+webpack+vue 章节目录 1.目标 2.实现 2.1合并库文件 2.2组织业务代码 2.3打包开发代码 2.4使用webpack-dev-server和热替换插件HotModuleR ...

  6. grunt,gulp,webpack前端打包工具的特性

    1.http://www.cnblogs.com/lovesong/p/6413546.html (gulp与webpack的区别) 2.http://blog.csdn.net/qq_3231263 ...

  7. 用gulp+webpack构建多页应用——记一次Node多页应用的构建过程

    通过参考网上的一些构建方法,当然也在开发过程中进行了一番实践,最终搭建了一套适用于当前多页应用的构建方案,当然该方案还处于draft版本,会在后续的演进过程中不断的优化. 个人觉得该方案的演进过程相对 ...

  8. gulp + webpack 构建多页面前端项目

    修改增加了demo地址 gulp-webpack-demo 之前在使用gulp和webpack对项目进行构建的时候遇到了一些问题,最终算是搭建了一套比较完整的解决方案,接下来这篇文章以一个实际项目为例 ...

  9. 前端自动化构建工具--Gulp&&Webpack

    前端构建工具的作用可以认为是对源项目文件或资源进行文件级处理,将文件或资源处理成需要的最佳输出结构和形式. 在处理过程中,我们可以对文件进行模块化引入.依赖分析.资源合并.压缩优化.文件嵌入.路径替换 ...

随机推荐

  1. PostGIS_导入shp格式的数据

    1.导入shp到PostGIS 开启PostGIS shp Loader,如下图: 打开View connection details....输入连接数据库的参数,如下: 连接成功后,点击Add Fi ...

  2. java中局部变量和成员变量主要是他们作用域的区别

    成员变量个是类内部:局部变量是定义其的方法体内部(或者方法体内部的某一程序块内——大括号,主要看定义的位置).另外,成员变量可以不显式初始化,它们可以由系统设定默认值:局部变量没有默认值,所以必须设定 ...

  3. 第二课 android项目结构

  4. SqlSever基础 datediff 计算两个时间相差多少年份

    镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...

  5. Creating HTML table with vertically oriented text as table header 表头文字方向

    AS an old question, this is more like info or reminder about vertical margin or padding in % that ta ...

  6. 常用的STL查找算法

    常用的STL查找算法 <effective STL>中有句忠告,尽量用算法替代手写循环:查找少不了循环遍历,在这里总结下常用的STL查找算法: 查找有三种,即点线面: 点就是查找目标为单个 ...

  7. plot bar chart using python

    Example import matplotlib.pyplot as plt import plotly.plotly as py # Learn about API authentication ...

  8. android tablelayout 显示图片

    当在tablelayout中显示图片时,设置imageView为固定大小时,会出现divide by zero 错误 将LayoutParams 改为 TableRow.LayoutParams即可 ...

  9. [转] Git SSH Key 生成步骤

    Git是分布式的代码管理工具,远程的代码管理是基于SSH的,所以要使用远程的Git则需要SSH的配置. github的SSH配置如下: 一 . 设置Git的user name和email: $ git ...

  10. 缓存技术之——Yii2性能优化之:缓存依赖

    Yii中的缓存依赖,简单来说就是将缓存和另外一个东西绑定在一起,如果另外一个东西发生变化,那么缓存也将发生变化.有点儿类似于JS中的触发事件(但是也不那么像),缓存的变动是依赖的东西所导致的. 依赖可 ...