gulp-webpack工程化实现electron
参考网站:
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的更多相关文章
- gulp & webpack整合
为什么需要前端工程化? 前端工程化的意义在于让前端这个行业由野蛮时代进化为正规军时代,近年来很多相关的工具和概念诞生.好奇心日报在进行前端工程化的过程中,主要的挑战在于解决如下问题:✦ 如何管理多个项 ...
- nodejs+gulp+webpack基础知识
nodejs+gulp+webpack基础知识 2019年08月22日 11:49:40 天府云创 阅读数 22 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文 ...
- 做一个gulp+webpack+vue的单页应用开发架子
1.目标 最近项目上的事情不多,根据我自己的开发习惯,决定开发一些简单的开发架子,方便以后事情多的时候直接套用.本文讲的一个gulp+webpack+vue的单页应用架子,想要达到的目的: 可以通过命 ...
- gulp + webpack + sass 学习
笔记: new webpack.optimize.CommonsChunkPlugin 核心作用是抽离公共代码,chunks:['index.js','main.js'] 另一个作用就是单独生成一个j ...
- gulp+webpack+vue
gulp+webpack+vue 章节目录 1.目标 2.实现 2.1合并库文件 2.2组织业务代码 2.3打包开发代码 2.4使用webpack-dev-server和热替换插件HotModuleR ...
- grunt,gulp,webpack前端打包工具的特性
1.http://www.cnblogs.com/lovesong/p/6413546.html (gulp与webpack的区别) 2.http://blog.csdn.net/qq_3231263 ...
- 用gulp+webpack构建多页应用——记一次Node多页应用的构建过程
通过参考网上的一些构建方法,当然也在开发过程中进行了一番实践,最终搭建了一套适用于当前多页应用的构建方案,当然该方案还处于draft版本,会在后续的演进过程中不断的优化. 个人觉得该方案的演进过程相对 ...
- gulp + webpack 构建多页面前端项目
修改增加了demo地址 gulp-webpack-demo 之前在使用gulp和webpack对项目进行构建的时候遇到了一些问题,最终算是搭建了一套比较完整的解决方案,接下来这篇文章以一个实际项目为例 ...
- 前端自动化构建工具--Gulp&&Webpack
前端构建工具的作用可以认为是对源项目文件或资源进行文件级处理,将文件或资源处理成需要的最佳输出结构和形式. 在处理过程中,我们可以对文件进行模块化引入.依赖分析.资源合并.压缩优化.文件嵌入.路径替换 ...
随机推荐
- Intent官方教程(5)在manifest中给组件添加<Intent-filter>
Receiving an Implicit Intent To advertise which implicit intents your app can receive, declare one o ...
- 把int放在一个char数组里(用于处理每一位数字)
sprintf(): #include <stdio.h> void put_int_with_space(int v) { char str[50]; //定义一个足够大的 ...
- Codeoforces 558 B. Duff in Love
// B. Duff in Love time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 从exchange2010上面删除特定主题或特定时间的邮件
昨天在上班的公交上接到同事电话,说他的的部门老大发错了一封邮件到另外一个同事邮箱了,问我能不 能去那个同事的邮箱里面删除,我一想,之前在网上看到过资料,到了公司趁那个误接收邮件的同事还没有来,在服务器 ...
- HTML系列(HTMl+CSS+JavaScript+Jquery)--un
HTML 指超文本标签语言. 点击查看更详细的HTML内容 包括:一.基本标签;二.常用标签;三.表单<form></form>;四.表格<table></t ...
- BZOJ 3202 项链
题目连接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3202 题意:一个项链由n个珠子组成.每个珠子有三个面,每个面上有一个数字,要求每个 ...
- spring事务管理-摘抄
原著网址 http://gcq04552015.iteye.com/blog/1666570 Spring是以代理的方式实现对事务的管理.我们在Action中所使用的Service对象,其实是代理对象 ...
- MYSQL主键自动增加的配置及auto_increment注意事项
文章一 原文地址: http://ej38.com/showinfo/mysql-202971.html 文章二: 点击转入第二篇文章 在数据库应用,我们经常要用到唯一编号.在MySQL中可通过字 ...
- [SAP ABAP开发技术总结]OPEN SQL
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- hdu 2112 (最短路+map)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2112 HDU Today Time Limit: 15000/5000 MS (Java/Others) ...