Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Support multiple entry points via new mains options, remove entry option #487

Merged
merged 1 commit into from Nov 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 24 additions & 14 deletions docs/api/README.md
Expand Up @@ -60,10 +60,10 @@ console.log(api.options.source); // /project/lib
```

```js
api.options.entry = 'app.js';
console.log(api.options.entry); // /project/src/app.js
api.options.mains.index = 'app.js';
console.log(api.options.mains.index); // /project/src/app.js
api.options.source = 'lib';
console.log(api.options.entry); // /project/lib/app.js
console.log(api.options.mains.index); // /project/lib/app.js
```

### `options.root`
Expand Down Expand Up @@ -135,21 +135,31 @@ Neutrino({
})
```

### `options.entry`
### `options.mains`

Set the main entry point for the application. If the option is not set, Neutrino defaults it to `index.*` - the
extension is resolved by webpack. The main file by default is not required to be in JavaScript format. If a relative
path is specified, it will be resolved relative to `options.source`; absolute paths will be used as-is.
Set the main entry points for the application. If the option is not set, Neutrino defaults it to:

```js
{
index: 'index'
}
```

Notice the entry point has no extension; the extension is resolved by webpack. If relative paths are specified,
they will be computed and resolved relative to `options.source`; absolute paths will be used as-is.

```js
Neutrino({
// if not specified, defaults to options.source + index

// relative, resolves to options.source + entry.js
entry: 'entry.js',

// absolute
entry: '/code/website/src/entry.js'
mains: {
// If not specified, defaults to options.source + index.*
index: 'index',

// Override to relative, resolves to options.source + entry.*
index: 'entry',

// Override to absolute path
index: '/code/website/src/entry.js'
}
})
```

Expand Down
2 changes: 1 addition & 1 deletion docs/cli/README.md
Expand Up @@ -88,7 +88,7 @@ index 3356802..d4d82ef 100644
devtool: 'source-map',
entry: {
index: [
+ 'babel-polyfill',
- 'babel-polyfill',
'/node/src/index.js'
]
},
Expand Down
46 changes: 33 additions & 13 deletions docs/creating-presets.md
Expand Up @@ -168,7 +168,9 @@ const middleware = (neutrino, options) => {
module.exports = {
options: {
source: 'lib',
entry: 'application.js'
mains: {
index: 'application.js'
}
},
use: [middleware]
}
Expand Down Expand Up @@ -260,27 +262,45 @@ module.exports = {
};
```

### `options.entry`
### `options.mains`

Set the main entry point for the application. If the option is not set, Neutrino defaults it to `index.*` - the
extension is resolved by webpack. If a relative path is specified, it will be resolved relative to `options.source`;
absolute paths will be used as-is.
Set the main entry points for the application. If the option is not set, Neutrino defaults it to:

The main file by default is not required to be in JavaScript format. It also potentially may be JSX, TypeScript, or any
other preprocessor language. These extensions should be specified in middleware at `neutrino.config.resolve.extensions`.
```js
{
index: 'index'
}
```

Notice the entry point has no extension; the extension is resolved by webpack. If relative paths are specified,
they will be computed and resolved relative to `options.source`; absolute paths will be used as-is.

By default these main files are not required to be in JavaScript format. They may also potentially be JSX, TypeScript,
or any other preprocessor language. These extensions should be specified in middleware at
`neutrino.config.resolve.extensions`.

```js
module.exports = neutrino => {
// if not specified, defaults to options.source + index
neutrino.options.entry;
// if not specified, defaults to an object with a single entry "index",
// resolved to options.source + index
neutrino.options.mains.index;
};

module.exports = {
options: {
// relative, resolves to options.source + entry.js
entry: 'entry.js',
// absolute
entry: '/code/website/src/entry.js'
mains: {
// If not specified, defaults to options.source + index
index: 'index',

// Override to relative, resolves to options.source + entry.*
index: 'entry',

// Override to absolute path
index: '/code/website/src/entry.js',

// Add additional main, resolves to options.source + admin.*
admin: 'admin'
}
}
};
```
Expand Down
36 changes: 22 additions & 14 deletions docs/customization/README.md
Expand Up @@ -109,27 +109,35 @@ module.exports = {
};
```

### `options.entry`
### `options.mains`

Set the main entry point for the application. If the option is not set, Neutrino defaults it to `index.*` - the
extension is resolved by webpack. If a relative path is specified, it will be resolved relative to `options.source`;
absolute paths will be used as-is.
Set the main entry points for the application. If the option is not set, Neutrino defaults it to:

The main file by default is not required to be in JavaScript format. It also potentially may be JSX, TypeScript, or
any other preprocessor language. These extensions should be specified in middleware at
`neutrino.config.resolve.extensions`.
```js
{
index: 'index'
}
```

Notice the entry point has no extension; the extension is resolved by webpack. If relative paths are specified,
they will be computed and resolved relative to `options.source`; absolute paths will be used as-is.

```js
module.exports = {
options: {
// Override to relative file, resolves to options.source + entry.*
entry: 'entry',
mains: {
// If not specified, defaults to options.source + index
index: 'index',

// Override to relative, resolves to options.source + entry.*
index: 'entry',

// Override to relative file, resolves to options.source + app.js
entry: 'app.js',

// Override to absolute file
entry: '/code/website/src/entry.js'
// Override to absolute path
index: '/code/website/src/entry.js',

// Add additional main, resolves to options.source + admin.*
admin: 'admin'
}
}
};
```
Expand Down
4 changes: 2 additions & 2 deletions docs/packages/html-template/README.md
@@ -1,7 +1,7 @@
# Neutrino HTML Template Middleware

`@neutrinojs/html-template` is Neutrino middleware for automatically creating HTML files for configured
entry-points.
entry points.

[![NPM version][npm-image]][npm-url]
[![NPM downloads][npm-downloads]][npm-url]
Expand Down Expand Up @@ -104,7 +104,7 @@ The following is a list of plugins and their identifiers which can be overridden

| Name | Description | Environments and Commands |
| --- | --- | --- |
| `html` | Automatically generates HTML files for configured entry-points. | all |
| `html` | Automatically generates HTML files for configured entry points. | all |

## Contributing

Expand Down
18 changes: 9 additions & 9 deletions docs/packages/library/README.md
Expand Up @@ -142,9 +142,9 @@ Logger.js.map 3.73 kB 0 [emitted] index
✨ Done in 1.51s.
```

You should specify a `main` property in your package.json pointing to the built entry point. Also when publishing your
project to npm, consider excluding your `src` directory by using the `files` property to whitelist `build`,
or via `.npmignore` to blacklist `src`.
You should specify a `main` property in your package.json pointing to your primary built main entry point. Also when
publishing your project to npm, consider excluding your `src` directory by using the `files` property to whitelist
`build`, or via `.npmignore` to blacklist `src`.

```json
{
Expand Down Expand Up @@ -386,11 +386,11 @@ To override the build configuration, start with the documentation on [customizat
`@neutrinojs/library` creates some conventions to make overriding the configuration easier once you are ready to make
changes.

By default the Library preset creates a single **main** `index` entry point to your library, and this maps to the
`index.*` file in the `src` directory. This means that the Library preset is optimized toward a main entry to your library.
Code not imported in the hierarchy of the `index` entry will not be output to the bundle. To overcome this you
must either define more entry points, or import the code path somewhere along the `index` hierarchy, or define
multiple configurations in your `.neutrinorc.js`.
By default Neutrino, and therefore this preset, creates a single **main** `index` entry point to your library, and this
maps to the `index.*` file in the `src` directory. This means that this preset is optimized toward a single main entry
to your library. Code not imported in the hierarchy of the `index` entry will not be output to the bundle. To overcome
this you must either define more mains via [`options.mains`](../../customization#optionsmains), import the code path
somewhere along the `index` hierarchy, or define multiple configurations in your `.neutrinorc.js`.

### Rules

Expand All @@ -409,7 +409,7 @@ _Note: Some plugins are only available in certain environments. To override them

| Name | Description | Environments and Commands |
| --- | --- | --- |
| `banner` | Injects source-map-support into the entry point of your application if detected in `dependencies` or `devDependencies` of your package.json. | Only when `source-map-support` is installed |
| `banner` | Injects source-map-support into the main entry points of your application if detected in `dependencies` or `devDependencies` of your package.json. | Only when `source-map-support` is installed |
| `clean` | Clears the contents of `build` prior to creating a production bundle. | `build` command |
| `minify` | Minifies source code using `BabiliWebpackPlugin`. From `@neutrinojs/minify`. | `NODE_ENV production` |
| `module-concat` | Concatenate the scope of all your modules into one closure and allow for your code to have a faster execution time in the browser. | `NODE_ENV production` |
Expand Down
19 changes: 10 additions & 9 deletions docs/packages/node/README.md
Expand Up @@ -150,9 +150,9 @@ index.js.map 3.73 kB 0 [emitted] index
```

You can either serve or deploy the contents of this `build` directory as a Node.js module, server, or tool. For Node.js
this usually means adding a `main` property to package.json pointing to the built entry point. Also when publishing your
project to npm, consider excluding your `src` directory by using the `files` property to whitelist `build`,
or via `.npmignore` to blacklist `src`.
this usually means adding a `main` property to package.json pointing to the primary main built entry point. Also when
publishing your project to npm, consider excluding your `src` directory by using the `files` property to whitelist
`build`, or via `.npmignore` to blacklist `src`.

```json
{
Expand Down Expand Up @@ -286,10 +286,11 @@ To override the build configuration, start with the documentation on [customizat
`@neutrinojs/node` creates some conventions to make overriding the configuration easier once you are ready to make
changes.

By default the Node.js preset creates a single **main** `index` entry point to your application, and this maps to the
`index.*` file in the `src` directory. This means that the Node.js preset is optimized toward a main entry to your app.
Code not imported in the hierarchy of the `index` entry will not be output to the bundle. To overcome this you
must either define more entry points, or import the code path somewhere along the `index` hierarchy.
By default Neutrino, and therefore this preset, creates a single **main** `index` entry point to your application, and this
maps to the `index.*` file in the `src` directory. This means that this preset is optimized toward a single main entry
to your application. Code not imported in the hierarchy of the `index` entry will not be output to the bundle. To overcome
this you must either define more mains via [`options.mains`](../../customization#optionsmains), import the code path
somewhere along the `index` hierarchy, or define multiple configurations in your `.neutrinorc.js`.

### Vendoring

Expand All @@ -312,10 +313,10 @@ _Note: Some plugins are only available in certain environments. To override them

| Name | Description | Environments and Commands |
| --- | --- | --- |
| `banner` | Injects source-map-support into the entry point of your application if detected in `dependencies` or `devDependencies` of your package.json. | Only when `source-map-support` is installed |
| `banner` | Injects source-map-support into the mains (entry points) of your application if detected in `dependencies` or `devDependencies` of your package.json. | Only when `source-map-support` is installed |
| `copy` | Copies all files from `src/static` to `build` when using `neutrino build`. | `build` command |
| `clean` | Clears the contents of `build` prior to creating a production bundle. | `build` command |
| `start-server` | Start a Node.js for a configured entry point or specified file. | `start` command |
| `start-server` | Start a Node.js for the first configured main entry point. | `start` command |
| `hot` | Enables Hot Module Replacement. | `start` command |
| `named-modules` | Enables named modules for improved debugging and console output. From `@neutrinojs/hot`. | `start` command |
| `module-concat` | Concatenate the scope of all your modules into one closure and allow for your code to have a faster execution time in the browser. | `NODE_ENV production` |
Expand Down
4 changes: 2 additions & 2 deletions docs/packages/preact/README.md
Expand Up @@ -235,7 +235,7 @@ module.exports = {
(neutrino) => {
neutrino.config
.entry('vendor')
.add('preact')
.add('preact');
}
]
};
Expand Down Expand Up @@ -273,7 +273,7 @@ load(App);
## Preact Devtools

To use the React Devtools for your Preact project, require the preact devtools during the `development` environment
within your `entry` file:
within your main entry file (typically `src/index`):

```js
if (process.env.NODE_ENV === 'development') {
Expand Down
6 changes: 4 additions & 2 deletions docs/packages/react-components/README.md
Expand Up @@ -175,7 +175,8 @@ These modules are ES-compatible modules, so they can be `import`ed as expected.
const YourCustomComponent = require('your-custom-component').default;
```

By default this preset creates an individual entry point for every top-level component found in `src/components`.
By default this preset creates an individual entry point for every top-level component found in `src/components`. These
are set and accessible via the API at [`neutrino.options.mains`](../../api#optionsmains).

## Previewer Components

Expand Down Expand Up @@ -277,7 +278,8 @@ To override the build configuration, start with the documentation on [customizat
See the [Web documentation customization](../web#customizing)
for preset-specific configuration to override.

By default this preset creates an individual entry point for every top-level component found in `src/components`.
By default this preset creates an individual entry point for every top-level component found in `src/components`. These
are set and accessible via the API at [`neutrino.options.mains`](../../api#optionsmains).

### Rules

Expand Down
25 changes: 24 additions & 1 deletion docs/packages/react/README.md
Expand Up @@ -146,6 +146,10 @@ The `@neutrinojs/web` preset loads assets relative to the path of your applicati
assets instead from a CDN, or if you wish to change to an absolute path for your application, customize your build to
override `output.publicPath`. See the [Customizing](#Customizing) section below.

For details on merging and overriding Babel configuration, such as supporting decorator syntax, read more
about using the [`compile-loader` `merge`](../compile-loader#advanced-merging) once you
are comfortable customizing your build.

## Preset options

You can provide custom options and have them merged with this preset's default options to easily affect how this
Expand Down Expand Up @@ -210,6 +214,25 @@ By following the [customization guide](../../customization/advanced.md) and know
`@neutrinojs/web`, you can override and augment the build by providing a function to your `.neutrinorc.js` use
array. You can also make these changes from the Neutrino API in custom middleware.

By default Neutrino, and therefore this preset, creates a single **main** `index` entry point to your application, and
this maps to the `index.*` file in the `src` directory. The extension is resolved by webpack. This value is provided by
`neutrino.options.mains` at `neutrino.options.mains.index`. This means that the Web preset is optimized toward the use
case of single-page applications over multi-page applications. If you wish to output multiple pages, you can detail
all your mains in your `.neutrinorc.js`.

```js
module.exports = {
options: {
mains: {
index: 'index', // outputs index.html from src/index.*
admin: 'admin', // outputs admin.html from src/admin.*
account: 'user' // outputs account.html from src/user.*
}
},
use: ['@neutrinojs/react']
}
```

#### Vendoring

By defining an entry point named `vendor` you can split out external dependencies into a chunk separate
Expand Down Expand Up @@ -250,7 +273,7 @@ First, install `react-hot-loader` as a dependency, this **must** be React Hot Lo

---

- From your `index` entry point (defaults to `src/index.*` from `neutrino.options.entry`), import an `AppContainer`
From your main entry point (defaults to `src/index.*` from `neutrino.options.mains.index`), import an `AppContainer`
from `react-hot-loader`. The main file may be named `index.js` or `index.jsx`. The extension is resolved by webpack.
- Wrap your top-level React component in the `AppContainer`.
- Perform the application render in a reusable function for initial load and subsequent reloads.
Expand Down