HaNdTriX / generator-chrome-extension-kickstart

Scaffold out a Web Extension http://yeoman.io
MIT License
239 stars 33 forks source link

Why not create a Pull Request to generator-chrome-extension? #3

Closed HaNdTriX closed 8 years ago

HaNdTriX commented 8 years ago

The reason why I chose a new project over a pull-request, was that the changes between the CommonJS way differs from the usemin way of wrapping things together.

generator-chrome-extension uses usemin. Therefor the entry point of our apps (e.g. popup or background) is the html document or the manifest.json file. But what is the entrypoint for my popup page? The manifest or the html document? This kind of magic increases the complexity of the build system and reduces the knowledge of what the build system is actually doing.

So when I decided to switch to a CommonJS approach, I realised that I don't need this magic anymore. I can require everything in one single entyfile.

app/background.js

var _ = require('lodash');
var messageSystem = require('./lib/messageSystem');
....

Later I reference this file in the manifest, some html document or in my code manually.

The same works for stylesheets:

app/styles/popup.less

@include 'node_modules/bootstrap/bootstrap.less';

or even better:

 @include 'node_modules/bootstrap/less/variables.less';   
 @include 'node_modules/bootstrap/less/grid.less';   

That brings us to the question how to define an entry file? I decided to interpret every file in the root of its directory of its specific type as entryfile.

./app/scripts/background.js  <-- Entryfile
./app/scripts/lib/livereload.js <-- This file has to be required manually

Everything else has to be required.

This makes it easy to reference these files later on.