Skip to content

Commit

Permalink
feat: add possibility to specify a custom entry file
Browse files Browse the repository at this point in the history
  • Loading branch information
haadcode authored and dignifiedquire committed Nov 17, 2016
1 parent e3a8617 commit 258f82f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 16 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ For example

```js
// awesome-tests module
const loadFixture = require('aegir/fixtures'
const loadFixture = require('aegir/fixtures')

const myFixture = loadFixture(__dirname, 'fixtures/coolfixture', 'awesome-tests')
```
Expand Down Expand Up @@ -169,6 +169,20 @@ $ aegir-build
$ gulp build
```

**Specifying a custom entry file for Webpack**

By default, `aegir` uses `src/index.js` as the entry file for Webpack. You can customize which file to use as the entry point by specifying `entry` field in your user configuration file. To do this, create `.aegir.js` file in your project's root diretory and add point the `entry` field to the file Webpack should use as the entry:

```javascript
module.exports = {
entry: "src/browser-index.js",
}
```

Webpack will use the specified file as the entry point and output it to `dist/<filename>`, eg. `dist/browser-index.js`.

If `.aegir.js` file is not present in the project, webpack will use `src/index.js` as the default entry file.

### Releasing

1. Run linting
Expand Down
3 changes: 2 additions & 1 deletion config/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ try {
module.exports = {
pkg: pkg,
customPkg: pkg.aegir || {},
customConfig: customConfig || {}
customConfig: customConfig || {},
entry: customConfig.entry || 'src/index.js'
}
5 changes: 3 additions & 2 deletions config/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ let user = require('./user')
// e.g. peer-id -> PeerId
const libraryName = upperFirst(camelCase(user.pkg.name))
const specific = merge(user.customPkg || {}, user.customPkg || {})
const entry = user.entry || 'src/index.js'

const shared = {
entry: [
path.resolve('src/index.js')
path.resolve(entry)
],
output: {
filename: 'index.js',
filename: entry.split('/').pop(),
library: libraryName,
path: 'dist'
},
Expand Down
3 changes: 1 addition & 2 deletions tasks/build/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ module.exports = (gulp) => {
const config = require('../../config/webpack')

const c = config
c.output.filename = 'index.js'
c.devtool = 'source-map'
c.plugins.push(
new webpack.optimize.DedupePlugin()
)

webpack(c, webpackDone(() => {
pump([
gulp.src('dist/index.js'),
gulp.src('dist/' + c.output.filename),
minifier({
mangle: false
}, uglify),
Expand Down
37 changes: 27 additions & 10 deletions tasks/lint.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
'use strict'

const path = require('path')

let sourceDirectories = [
'*.js',
'bin/**',
'config/**/*.js',
'test/**/*.js',
'src/**/*.js',
'tasks/**/*.js',
'examples/**/*.js',
'benchmarks/**/*.js'
]

// Get custom entry file's directory and add it to the source directories
try {
const customConfig = require(path.resolve('.aegir.js'))
if (customConfig.entry) {
// Get the entry file path and remove the filename from it
const entryDir = customConfig.entry.split('/').slice(0, -1).join('/')
if (entryDir !== '') {
sourceDirectories.push(entryDir + '/**/*.js')
}
}
} catch (err) {
}

module.exports = (gulp) => {
gulp.task('lint', () => {
const eslint = require('gulp-eslint')

return gulp.src([
'*.js',
'bin/**',
'config/**/*.js',
'test/**/*.js',
'src/**/*.js',
'tasks/**/*.js',
'examples/**/*.js',
'benchmarks/**/*.js'
])
return gulp.src(sourceDirectories)
.pipe(eslint(`${__dirname}/../config/eslintrc.yml`))
.pipe(eslint.format())
.pipe(eslint.failAfterError())
Expand Down

0 comments on commit 258f82f

Please sign in to comment.