All Projects → chentsulin → Webpack Target Electron Renderer

chentsulin / Webpack Target Electron Renderer

Licence: mit
webpack target function for electron renderer

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Webpack Target Electron Renderer

Learn Webpack
Webpack lesson for beginners.
Stars: ✭ 111 (-3.48%)
Mutual labels:  webpack
Knowledge
文档着重构建一个完整的「前端技术架构图谱」,方便 F2E(Front End Engineering又称FEE、F2E) 学习与进阶。
Stars: ✭ 1,620 (+1308.7%)
Mutual labels:  webpack
Serverless Webpack
Serverless plugin to bundle your lambdas with Webpack
Stars: ✭ 1,595 (+1286.96%)
Mutual labels:  webpack
Bootstrap Validate
A simple Form Validation Library for Bootstrap 3 and Bootstrap 4 not depending on jQuery.
Stars: ✭ 112 (-2.61%)
Mutual labels:  webpack
Universal React Redux
🧐 A sensible universal starter kit for React + Redux
Stars: ✭ 112 (-2.61%)
Mutual labels:  webpack
Alpha
Craft your own web-based chatbot
Stars: ✭ 113 (-1.74%)
Mutual labels:  webpack
Easywebpack Cli
A Powerful Cross-platform Webpack CLI Tool
Stars: ✭ 110 (-4.35%)
Mutual labels:  webpack
Raw.macro
Read file contents at build time via babel-plugin-macros. webpack-less raw-loader
Stars: ✭ 115 (+0%)
Mutual labels:  webpack
Webpack Seed
🚀 A Multi-Page Application base on webpack and babel. webpack搭建基于ES6,支持模板的多页面项目
Stars: ✭ 113 (-1.74%)
Mutual labels:  webpack
Csdwheels
一套基于原生JavaScript开发的插件,无依赖、体积小
Stars: ✭ 114 (-0.87%)
Mutual labels:  webpack
Node Hot Loader
Hot module replacement (hot reload) for Node.js applications. Develop without server restarting.
Stars: ✭ 111 (-3.48%)
Mutual labels:  webpack
Sass Vars Loader
Use Sass variables defined in Webpack config or in external Javascript or JSON files
Stars: ✭ 112 (-2.61%)
Mutual labels:  webpack
Seven
Eleventy template using Bootstrap, Sass, Webpack, Vue.js powered search, includes lots of other features
Stars: ✭ 114 (-0.87%)
Mutual labels:  webpack
Chrome Extension Starter Kit
A starter kit for developing chrome extensions with React.
Stars: ✭ 112 (-2.61%)
Mutual labels:  webpack
React Workshop
⚒ 🚧 This is a workshop for learning how to build React Applications
Stars: ✭ 114 (-0.87%)
Mutual labels:  webpack
Nutmeg
Build, test, and publish vanilla Web Components with a little spice
Stars: ✭ 111 (-3.48%)
Mutual labels:  webpack
Basys
Toolbox for building full-stack Vue.js apps
Stars: ✭ 113 (-1.74%)
Mutual labels:  webpack
React Redux Auth0 Kit
Minimal starter boilerplate project with CRA, React, Redux, React Router and Auth0 authentication
Stars: ✭ 115 (+0%)
Mutual labels:  webpack
Web Extension Starter
Typescript, React, Redux, Styled-Component and Webpack based sample extension boilerplate. Runs on Chrome and Firefox. Sample chrome extension.
Stars: ✭ 115 (+0%)
Mutual labels:  webpack
Babel Plugin Prismjs
A babel plugin to use PrismJS with standard bundlers.
Stars: ✭ 114 (-0.87%)
Mutual labels:  webpack

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].