• Stars
    star
    115
  • Rank 305,916 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

webpack target function for electron renderer

webpack-target-electron-renderer

NPM version Build Status Test coverage Dependency Status

webpack target function for electron renderer

Install

$ npm install webpack-target-electron-renderer

Usage

var webpackTargetElectronRenderer = require('webpack-target-electron-renderer');

var options = {
  entry: entry,
  output: output,
  module: {
    loaders: loaders
  },
  devtool: opts.devtool,
  resolve: {
    extensions: extensions,
    packageMains: ['webpack', 'browser', 'web', 'browserify', ['jam', 'main'], 'main']
  }
}

options.target = webpackTargetElectronRenderer(options)

See also electron-react-boilerplate.

API

webpackTargetElectronRenderer(options)

options

Required Type: object

just like the object that you used to export by webpack.config.js.

How this module works

There are some built-in webpack build targets, such as 'web', 'node', 'electron', includes several important modules and global variables resolving rules and templates for chunk and hot-update functionalities.

In electron, there are two different kinds of processes: main and renderer. electron-main is almost the same as node environment and just need to set all of electron built-in modules as externals. However, electron-renderer is a little bit different, it's just like a mix environment between browser and node. So we need to provide a target using JsonpTemplatePlugin, FunctionModulePlugin for browser environment and NodeTargetPlugin and ExternalsPlugin for commonjs and electron bulit-in modules.

Below is the code about how webpack apply target option:

// webpack/WebpackOptionsApply.js

WebpackOptionsApply.prototype.process = function(options, compiler) {
  ...
  if(typeof options.target === "string") {
		switch(options.target) {
			case "web":
				...
			case "webworker":
				...
			case "node":
			case "async-node":
				...
			case "node-webkit":
				...
			case "atom":
			case "electron":
				...
			default:
				throw new Error("Unsupported target '" + options.target + "'.");
		}
	} else if(options.target !== false) {
		options.target(compiler);
	} else {
		throw new Error("Unsupported target '" + options.target + "'.");
	}
	...
}

As you can see, we can provide a function as target and then it will go into this else if branch:

} else if(options.target !== false) {
  options.target(compiler);
} else {

That's it! This is the basic mechanism about how this module works.

Source code is only 32 LoC now, so it should not be so hard to understand.

Note: webpack#1467 and webpack#2181 has been merged and released (>= v1.12.15), so we can use on webpack 1.x and 2.x now.

Migrate to webpack 2 or webpack 1 >= 1.12.15

Added target: 'electron-renderer' to your webpack.config.js instead of using this module:

module.exports = {
  target: 'electron-renderer',
  // ...others
};

See the example here.

License

MIT © C.T. Lin

More Repositories

1

awesome-graphql

Awesome list of GraphQL
14,576
star
2

awesome-react-renderer

Awesome list of React Renderer
1,721
star
3

sweetalert-react

Declarative SweetAlert in React
JavaScript
240
star
4

react-native-counter-ios-android

Minimal implement of redux counter example on ReactNative iOS and Android
JavaScript
238
star
5

watch-nba

Watch NBA game in your terminal.
JavaScript
98
star
6

koa-graphql-relay-example

Todo example for koa-graphql and relay
JavaScript
98
star
7

redux-boilerplate

Another boilerplate for personal usage
JavaScript
55
star
8

generator-redux-app

Scaffold out a redux app
JavaScript
55
star
9

koa-context-validator

A robust context validator for koajs. Use Joi behind the scenes.
TypeScript
54
star
10

micro-koa

Creating microservices with koa inspired by zeit/micro
JavaScript
46
star
11

koa-bearer-token

Bearer token parser middleware for koa
TypeScript
33
star
12

react-redux-sweetalert

SweetAlert with Redux-style actions, reducers API
JavaScript
31
star
13

react-karaoke-lyric

Display karaoke lyric progress via React
JavaScript
31
star
14

redux-intro

http://chentsulin.github.io/redux-intro
JavaScript
30
star
15

simple-koa2-example

JavaScript
19
star
16

bottender-kamigo-example

以 Bottender 實作的卡米狗範例
JavaScript
18
star
17

react-native-intro

An introduction to react native
JavaScript
18
star
18

styled-css-modules-component

Build styled component with css-modules
JavaScript
15
star
19

react-scrolla

React Infinite Scroll Component
JavaScript
14
star
20

generator-koa2

Scaffold out a koa2 app
JavaScript
12
star
21

sublime-react-snippet

a collection of Sublime React Snippets
12
star
22

modernweb2016-graphql-relay-intro

JavaScript
11
star
23

learn-programming

Resource of web programming course
JavaScript
9
star
24

radium-intro

http://chentsulin.github.io/radium-intro
JavaScript
8
star
25

react-window-state

Pass updated window width and height as props on resize
JavaScript
8
star
26

awesome-conference-playlists

video playlist collection for awesome conferences
7
star
27

github-latest-release

Get latest release information from github repository using github api
JavaScript
7
star
28

Create-Native-App-in-30-days

第八屆 iTHome 鐵人賽:使用 Modern Web 技術來打造 Native App
7
star
29

eslint-plugin-pangu

Eslint rules for whitespaces between CJK and half-width characters
JavaScript
7
star
30

koa-snake-res

Snake case json response transform middleware for koa
JavaScript
5
star
31

loaders-by-extension

A mirror library from webpack/react-starter
JavaScript
5
star
32

react-botui

React bindings for BotUI
JavaScript
5
star
33

redux-example

WIP
JavaScript
5
star
34

line-flex-ui

Component library for LINE flex messages
JavaScript
5
star
35

sequelize-test-utils

Test utils for sequelize
JavaScript
5
star
36

rectimage

Crop image to rectangle
JavaScript
5
star
37

http-client-debug

debug utils for http-client
JavaScript
4
star
38

kktix-event-listener

JavaScript
4
star
39

electron-boilerplate

JavaScript
4
star
40

bottender-v1-order-example

JavaScript
4
star
41

start-learning-react-native

Objective-C
4
star
42

messenger-one-time-notification-example

「如何發送一次性通知?帶你了解 Messenger One-Time Notification」 的文章範例。
JavaScript
4
star
43

generator-electron-react

WIP
JavaScript
3
star
44

java-design-patterns

Simple java design pattern implements as reference
Java
3
star
45

node-addon-examples

node-addon-helloworld
Python
3
star
46

is-lrc

Check if a string is LRC
JavaScript
2
star
47

lrcf

Transform LRC to JSON data(WIP)
JavaScript
2
star
48

ava-css-modules-issue-repro

Demonstrate issue (ava with css-modules)
JavaScript
2
star
49

a-collection-of-frontend-libs

2
star
50

react-without-__DEV__

JavaScript
2
star
51

generator-cnm

Fork from sindresorhus/generator-nm for personal usage
JavaScript
2
star
52

esm-quizzes

ESM 小測驗
JavaScript
2
star
53

live-coding

JavaScript
1
star
54

start-learning-elm

Elm
1
star
55

TCP-socket-server

TCP-socket-server
JavaScript
1
star
56

babel-plugin-transform-move-comments-to-top

Move comments to top of the file
JavaScript
1
star
57

frequency-to-midi-note-number

Mapping from Frequency to MIDI note number
JavaScript
1
star
58

three-demo

JavaScript
1
star
59

bottender-ntu-demo

Bottender Demo for NTUOSC
JavaScript
1
star
60

require-conf

require config file via NODE_ENV
JavaScript
1
star
61

swc-issue-5989-swc-minify

JavaScript
1
star
62

appresource

Rails, Laravel -like resource routes for expres
JavaScript
1
star
63

bind-handler

Bind event handlers to this less verbose
JavaScript
1
star
64

react-apollo-create-fragment-container

Relay style createFragmentContainer for React Apollo
JavaScript
1
star
65

mails-sender

WIP
JavaScript
1
star
66

is-npm-linked

JavaScript
1
star
67

nextjs-issue-40178-bundle-client-buffer

JavaScript
1
star
68

node-base64

base64 helper for node
JavaScript
1
star
69

bottender-v1-kamigo-example

JavaScript
1
star
70

create-action-types

create flux ActionTypes less verbose
JavaScript
1
star
71

update-schema

A module and cli tool for updating graphql schema
JavaScript
1
star