Giter VIP home page Giter VIP logo

webpack-chrome-extension's Introduction

Webpack Chrome extension

IMPORTANT!!!

I am leaving this project in favor of Create Chrome Extension. It is standalone npm package and should be more maintanable.

Description

Bootstrap project for developing any kind Chrome extensions with all javascript features like NPM packages, Webpack, Babel, React and almost everything you want.

Turn this

manifest.json

{
  "content_scripts": [{
    "js": ["jquery.min.js", "jquery-spellchecker.min.js", "jquery-megamask.min.js", "jquery-scrolltie.min.js", "my-plugins.js", "app.js"],
    "css": ["app.css"]
  }]
}

Into this

manifest.json

{"content_scripts": [{"js": ["app.js"]}]}

Run npm install jquery jquery-spellchecker jquery-megamask jquery-scrolltie --save

app.js

import 'jquery'
import 'jquery-spellchecker'
import 'jquery-megamask'
import 'jquery-scrolltie'
import './my-plugins'

import "./app.css"

// Here start my application
$('input').spellchecker()

Extension features support

Installation

  1. npm install
  2. npm install gulp -g
  • if there is problem with missing gulpfile, uninstall npm uninstall gulp -g and install again. You have probably old non-babel compatible version

Usage

  • Whole repository (package) is simple example extension.
  • Check src/manifest.json for basic usage of background script, content script, action popup and chrome url overrides.
  • All scripts and/or html pages from manifest.json are piped through preprocessor and prepared for using all features.
  • When your extension does exactly what you want, you can run gulp -p for creating production .crx build.
  • All your codebase belongs only to src/ directory
  • In your scripts you can use npm packages, babel, react (jsx), styles (with preprocessors) and any modern javascript feature you know.

How to run development environment

You should do this before editing any code to see how it works.

  1. run gulp which will start webpack-dev-server
  2. in Chrome open chrome://extensions/
  3. check Developer mode
  4. click on Load unpacked extension
  5. add REPOSITORY_DIRECTORY/build
  6. Now you can check background script via link in extension Inspect views: background page and you will see some messages in console
  7. Navigate to any http or https page and open development tools and console. You can see messages from content scripts.
  8. Find extension icon (puzzle image) right from adress bar.
  9. Click with left mouse button to show html content
  10. Click with right mouse button and select Inspect Popup. Then in console you can see some messages
  11. You can edit your codebase with almost 100% hot/full reload support.

How to build extension

  1. run gulp -p
  2. It will compile scripts, styles and other assets into release/build/
  3. It will make chrome extension into release/build.crx with certificate release/build.pem

TODO

Done

  • Make manifest.json dynamic based on package.json name, description, version.
  • Move everything from build directory and leave it only for building development extenstion.
  • Make production build. Replace injector scripts with final builded one.
  • Make Hot reload works. There is problem with including hot reload chunks which are included via new script tag into DOM. new code is then eval in default (window) context and not in context of extension. Have to do same hack as you can see in injector files and download chunks via XMLHttpRequest.
  • Move config/manifest.json, util/make_injector.js and util/make_manifest.js somewhere out of src to keep src in full will of developer
  • Create extension from build process and move it into release/
  • Test assets base64 support
  • Add asset example. Icon for actions

Future

  • Split webpack config into core and user parts. Core are necessary for working this whole thing and user are developer customs.
  • Allow to have "static" files which will be merged into build
  • Allow to reload extension when popup html file changed
  • Detect Chrome path for building extension
  • Solve Hot reload fix better than overriding file in /node_modules. It is really ugly and hacky
  • Create example repository with React app
  • Test assets without base64
  • Allow to define entry scripts other way than define them in manifest.json
  • Add support for extension updating

Licence

Webpack Chrome Extension is released under the MIT License.

webpack-chrome-extension's People

Contributors

dev-msp avatar ladas-larry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

webpack-chrome-extension's Issues

Keep devtools open during hot reload

Hey, great stuff. Thank you.

I just got this going and i noticed every time i save and it hot reloads it refreshes and closes dev tools.
Do you know if there is a way around that?

Docs

Could you add some comments about how webpack configuration works. I want to add Popup and I'm not very sure how.

Uncaught ReferenceError: webpackJsonp is not defined

Hey there,

great repo. helped me a lot to bootstrap my application. I run into one scenario, you might have an Idea.
I want to load a module delayed, depending on the interaction of the customer. I use
require.ensure("modulename") to do this. It works, there is a dedicated 0.0.js file created which will only be loaded when the customers clicks a button.

It works very well in the newtab.js but in the content.js which is injected in every page that the customer opens, i get a Uncaught ReferenceError: webpackJsonp is not defined (in the development env).

Do you know if the content.js is executed in a different namespace or something similar?
Would be a great feature to get this working.

thanks again

Do not understand Step 5 in "How to run development environment"

Firstly, I have run the command npm install and get the node_module in the folder.
After step 4, the Browse For Folder small window appears, and do not know what path I should use in the textfield of Folder.

 5. add REPOSITORY_DIRECTORY/build

I guess that REPOSITORY_DIRECTORY is schovi/webpack-chrome-extension. But I cannot find the build folder there. What should I do?

Thank you.

too many redirects

Hello,
When I execute "gulp" I get the following errors:
ERROR in ./~/ws/lib/WebSocketServer.js Module not found: Error: Cannot resolve module 'tls' in /home/.../webpack-chrome-extension/node_modules/ws/lib

ERROR in ./~/options/lib/options.js Module not found: Error: Cannot resolve module 'fs' in /home/.../webpack-chrome-extension/node_modules/options/lib

But then it says:
webpack: bundle is now VALID.

And then when I open the background page I get:
Failed to load resource: net::ERR_TOO_MANY_REDIRECTS
*At first I got Insecure connection error but I found an answer for it in the issues.

I'm using Ubuntu 14.04 and Chrome 47

b.t.w when I execute "gulp -p" I'm getting some errors but the extension is working.

Thanks!

Can we change devServer setting to https ?

As title described,
I tried adding https: true in dev-env/webpack.server.js and
change every occurrence of http to https , but can't work out as expected,
(I have to let chrome explicit access to https://localhost:3001/content.js)
If I can't change that setting, then I can't let content.js works in
ex: https://facebook.com and almost most of the site.
Do we have a better solution for this, since development for most of the site that is https based
is a non-trivial thing.

Strip out less, stylus, sass loaders

First of all, big thanks to you for this contribution, great work!

Not all devs use these loaders and mostly not use them all at once. sass loader also require node-gyp step so I already encountered some problems on windows. I guess cool solution for this - make some webpack.config hook for user, so he could override configuration.

Like search for some webpack.chrome-extension.config,js file in the root of user project and merge it then with default config.

Doesn't run on windows

The file dev-env/util/remove.js has some utility functions for building paths. However it assumes the directory separator is a "/", when on windows it is a "".

I think it can use something like path.sep

error: ERR_INSECURE_RESPONSE

  1. npm install
  2. npm run dev
  3. load unpack extension from build folder
  4. inspect background page: https://localhost:3001/background/index.js Failed to load resource: net::ERR_INSECURE_RESPONSE

Full reload

After changing the background script extension says "The following couldn't be hot updated: (They would need a full reload!)". Wouldn't it be more convenient to run chrome.runtime.reload(); in such cases? Or at least have an option that would allow full reload.

Failed to write file

Env: Win10
Err Message:

Making injector 'popup/index.js'
[16:45:24] 'manifest' errored after 33 ms
[16:45:24] Error: ENOENT: no such file or directory, open 'E:\web\extensions\qwt\build\popup\index.js'
    at Error (native)
    at Object.fs.openSync (fs.js:634:18)
    at Object.fs.writeFileSync (fs.js:1327:33)
    at exports.default (E:/web/extensions/qwt/dev-env/manifest/processor/lib/script.js:38:8)
    at exports.default (E:/web/extensions/qwt/dev-env/manifest/processor/lib/html.js:39:3)
    at process (E:/web/extensions/qwt/dev-env/manifest/processor/action.js:6:16)
    at exports.default (E:/web/extensions/qwt/dev-env/manifest/processor/action.js:21:3)
    at E:/web/extensions/qwt/dev-env/manifest/index.js:66:9
    at Array.forEach (native)
    at Manifest.processManifest (E:/web/extensions/qwt/dev-env/manifest/index.js:64:16)

how to solve this problem??

Insecure response error

I'm seeing this error in the console when navigating to any page:

Failed to load resource: net::ERR_INSECURE_RESPONSE https://localhost:3001/app/index.js

Steps to reproduce:

  1. npm install && gulp
  2. Load extension from /build/ folder
  3. Open console or inspect background view

Is page_action not supported?

Hi, thanks for the quick response to #5 , it works great?
one to thing to bother, when I tried replacing browser_action with page_action
and in background script, I let if url == ...., then chrome.pageAction.show....
but I found that if I change browser_action to page_action, popup/index.html will be compiled into build, is that intentional, how can I config that?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.