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

Allow usage of multiple same plugins, map mains to html plugins #509

Merged
merged 1 commit into from Dec 2, 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
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -22,4 +22,4 @@ script:
- yarn validate:eslintrc
- yarn lint
- yarn build
- yarn test
- yarn test:all
8 changes: 6 additions & 2 deletions docs/packages/banner/README.md
Expand Up @@ -47,7 +47,9 @@ neutrino.use(banner);
neutrino.use(banner, {
banner: `require('source-map-support').install();`,
raw: true,
entryOnly: true
entryOnly: true,
// Override pluginId to add an additional banner plugin instance
pluginId: 'banner'
});
```

Expand All @@ -69,7 +71,9 @@ module.exports = {
['@neutrinojs/banner', {
banner: `require('source-map-support').install();`,
raw: true,
entryOnly: true
entryOnly: true,
// Override pluginId to add an additional banner plugin instance
pluginId: 'banner'
}]
]
};
Expand Down
8 changes: 6 additions & 2 deletions docs/packages/clean/README.md
Expand Up @@ -43,7 +43,9 @@ neutrino.use(clean);
// Usage shows the default values of this middleware:
neutrino.use(clean, {
paths: [],
root: neutrino.options.root
root: neutrino.options.root,
// Override pluginId to add an additional banner plugin instance
pluginId: 'clean'
});
```

Expand All @@ -60,7 +62,9 @@ module.exports = {
use: [
['@neutrinojs/clean', {
paths: [],
root: neutrino.options.root
root: neutrino.options.root,
// Override pluginId to add an additional banner plugin instance
pluginId: 'clean'
}]
]
};
Expand Down
10 changes: 8 additions & 2 deletions docs/packages/compile-loader/README.md
Expand Up @@ -41,7 +41,9 @@ const compile = require('@neutrinojs/compile-loader');
neutrino.use(compile, {
include: [],
exclude: [],
babel: {}
babel: {},
ruleId: 'compile',
useId: 'babel'
});
```

Expand All @@ -53,7 +55,9 @@ module.exports = {
['@neutrinojs/compile-loader', {
include: [],
exclude: [],
babel: {}
babel: {},
ruleId: 'compile',
useId: 'babel'
}]
]
};
Expand All @@ -65,6 +69,8 @@ module.exports = {
[`Rule.exclude`](https://webpack.js.org/configuration/module/#rule-exclude)
- `babel` is a [Babel configuration object](https://babeljs.io/docs/usage/api/#options), consumed by babel-loader. Use
this to set properties such as `presets`, `plugins`, and `env`.
- `ruleId` is the identifier to the compiler loader rule. Override this to add an additional compile-loader instance
- `useId` is the identifier for the babel loader. Override this to change the identifier.

## Merging Babel Configuration

Expand Down
7 changes: 5 additions & 2 deletions docs/packages/copy/README.md
Expand Up @@ -43,7 +43,8 @@ neutrino.use(copy);
// Usage shows the default values of this middleware:
neutrino.use(copy, {
patterns: [],
options: {}
options: {},
pluginId: 'copy'
});
```

Expand All @@ -60,7 +61,8 @@ module.exports = {
use: [
['@neutrinojs/copy', {
patterns: [],
options: {}
options: {},
pluginId: 'copy'
}]
]
};
Expand All @@ -71,6 +73,7 @@ See their docs for details on valid values to specify.

- `patterns`: An array of patterns specifying copy operations.
- `options`: An object specifying copy options.
- `pluginId`: The plugin identifier. Override this to add an additional copy plugin instance.

## Customization

Expand Down
8 changes: 6 additions & 2 deletions docs/packages/html-template/README.md
Expand Up @@ -51,7 +51,9 @@ neutrino.use(template, {
keepClosingSlash: true,
collapseWhitespace: true,
preserveLineBreaks: true
}
},
// Override pluginId to add an additional html-template plugin instance
pluginId: 'html'
});

// Most commonly, you will want to override the initial page title:
Expand All @@ -78,7 +80,9 @@ module.exports = {
keepClosingSlash: true,
collapseWhitespace: true,
preserveLineBreaks: true
}
},
// Override pluginId to add an additional html-template plugin instance
pluginId: 'html'
}]
]
};
Expand Down
127 changes: 127 additions & 0 deletions docs/packages/imagemin/README.md
@@ -0,0 +1,127 @@
# Neutrino Imagemin Middleware

`@neutrinojs/imagemin` is Neutrino middleware for optimizing images with imagemin.

[![NPM version][npm-image]][npm-url]
[![NPM downloads][npm-downloads]][npm-url]
[![Join the Neutrino community on Spectrum][spectrum-image]][spectrum-url]

## Requirements

- Node.js v6.10+
- Yarn or npm client
- Neutrino v7

## Installation

`@neutrinojs/imagemin` can be installed via the Yarn or npm clients.

#### Yarn

```bash
❯ yarn add @neutrinojs/imagemin
```

#### npm

```bash
❯ npm install --save @neutrinojs/imagemin
```

## Usage

`@neutrinojs/imagemin` can be consumed from the Neutrino API, middleware, or presets. Require this package
and plug it into Neutrino:

```js
// Using function middleware format
const images = require('@neutrinojs/image-loader');
const imagemin = require('@neutrinojs/imagemin');

// Use with default options
neutrino.use(images);
neutrino.use(imagemin);

// Usage showing default options
neutrino.use(imagemin, {
imagemin: {
plugins: [
gifsicle(),
svgo(),
pngquant(),
mozjpeg(),
webp()
]
},
plugin: {
name: '[path][name].[ext]',
test: /\.(png|jpg|jpeg|gif|webp)$/
},
useId: 'imagemin',
rules: ['svg', 'img'],
pluginId: 'imagemin',
});
```

```js
// Using object or array middleware format

// Use with default options
module.exports = {
use: ['@neutrinojs/imagemin']
};

// Usage showing default options
module.exports = {
use: [
['@neutrinojs/imagemin', {
imagemin: {},
plugin: {
name: '[path][name].[ext]',
test: /\.(png|jpg|jpeg|gif|webp)$/
},
rules: ['svg', 'img'],
pluginId: 'imagemin'
}]
]
};
```

- `imagemin`: Set options for [imagemin](https://github.com/imagemin/imagemin#options).
- `plugin`: Set options for [imagemin-webpack](https://github.com/itgalaxy/imagemin-webpack#standalone-plugin)'s ImageminWebpackPlugin.
- `rules`: Specify rules for the application of imagemin.
- `pluginId`: The imagemin plugin identifier. Override this to add an additional imagemin plugin instance.

## Customization

`@neutrinojs/imagemin` creates some conventions to make overriding the configuration easier once you are
ready to make changes.

### Rules

The following is a list of rules and their identifiers which can be overridden:

| Name | Description | Environments and Commands |
| --- | --- | --- |
| `img` | Optimize JPEG, PNG, GIF, and WEBP files imported from modules. Contains a single loader named `imagemin`. | all |
| `svg` | Optimize SVG files imported from modules. Contains a single loader named `imagemin`. | all |

### Plugins

The following is a list of plugins and their identifiers which can be overridden:

| Name | Description | Environments and Commands |
| --- | --- | --- |
| `imagemin` | Optimize any images added by other webpack plugins (e.g. `copy-webpack-plugin`). | all |

## Contributing

This middleware is part of the [neutrino-dev](https://github.com/mozilla-neutrino/neutrino-dev) repository, a monorepo
containing all resources for developing Neutrino and its core presets and middleware. Follow the
[contributing guide](../../contributing) for details.

[npm-image]: https://img.shields.io/npm/v/@neutrinojs/imagemin.svg
[npm-downloads]: https://img.shields.io/npm/dt/@neutrinojs/imagemin.svg
[npm-url]: https://npmjs.org/package/@neutrinojs/imagemin
[spectrum-image]: https://withspectrum.github.io/badge/badge.svg
[spectrum-url]: https://spectrum.chat/neutrino
2 changes: 1 addition & 1 deletion docs/packages/library/README.md
Expand Up @@ -411,7 +411,7 @@ _Note: Some plugins are only available in certain environments. To override them
| --- | --- | --- |
| `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` |
| `minify` | Minifies source code using `BabelMinifyWebpackPlugin`. 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` |

### Override configuration
Expand Down
10 changes: 8 additions & 2 deletions docs/packages/pwa/README.md
Expand Up @@ -43,7 +43,9 @@ neutrino.use(pwa);

// Usage showing overriding options
neutrino.use(pwa, {
relativePaths: true
relativePaths: true,
// Override pluginId to add an additional pwa plugin instance
pluginId: 'pwa'
});
```

Expand All @@ -58,7 +60,11 @@ module.exports = {
// Usage showing overriding options
module.exports = {
use: [
['@neutrinojs/pwa', { relativePaths: true }]
['@neutrinojs/pwa', {
relativePaths: true,
// Override pluginId to add an additional pwa plugin instance
pluginId: 'pwa'
}]
]
};
```
Expand Down
10 changes: 8 additions & 2 deletions docs/packages/start-server/README.md
Expand Up @@ -43,7 +43,11 @@ const server = require('@neutrinojs/start-server');
neutrino.use(server);

// Usage with custom server file to start
neutrino.use(server, { name: 'custom.js' });
neutrino.use(server, {
name: 'custom.js',
// Override pluginId to add an additional start-server plugin instance
pluginId: 'start-server'
});
```

```js
Expand All @@ -59,7 +63,9 @@ module.exports = {
module.exports = {
use: [
['@neutrinojs/start-server', {
name: 'custom.js'
name: 'custom.js',
// Override pluginId to add an additional start-server plugin instance
pluginId: 'start-server'
}]
]
};
Expand Down
2 changes: 1 addition & 1 deletion docs/packages/vue/README.md
Expand Up @@ -15,7 +15,7 @@
- Automatic creation of HTML pages, no templating necessary
- Hot Module Replacement support
- Tree-shaking to create smaller bundles
- Production-optimized bundles with Babili minification, easy chunking, and scope-hoisted modules for faster execution
- Production-optimized bundles with Babel minification, easy chunking, and scope-hoisted modules for faster execution
- Easily extensible to customize your project as needed

## Requirements
Expand Down
5 changes: 2 additions & 3 deletions docs/packages/web/README.md
Expand Up @@ -15,7 +15,7 @@
- Automatic creation of HTML pages, no templating necessary
- Hot Module Replacement support
- Tree-shaking to create smaller bundles
- Production-optimized bundles with Babili minification, easy chunking, and scope-hoisted modules for faster execution
- Production-optimized bundles with Babel minification, easy chunking, and scope-hoisted modules for faster execution
- Easily extensible to customize your project as needed

## Requirements
Expand Down Expand Up @@ -236,7 +236,6 @@ module.exports = {
image: false,
style: false,
font: false,
image: false,
manifest: false,

// Example: Remove console and debugger from output
Expand Down Expand Up @@ -350,7 +349,7 @@ _Note: Some plugins are only available in certain environments. To override them
| `hot` | Enables Hot Module Replacement. From `@neutrinojs/hot`. | `start` command |
| `copy` | Copies files during build, defaults from `src/static` to `build/static`. From `@neutrinojs/copy` | `build` command |
| `clean` | Removes the `build` directory prior to building. From `@neutrinojs/clean`. | `build` command |
| `minify` | Minifies source code using `BabiliWebpackPlugin`. From `@neutrinojs/minify`. | `NODE_ENV production` |
| `minify` | Minifies source code using `BabelMinifyWebpackPlugin`. 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` |

### Override configuration
Expand Down
4 changes: 2 additions & 2 deletions docs/webpack-chain.md
Expand Up @@ -1032,7 +1032,7 @@ neutrino.config
.when(process.env.NODE_ENV === 'production', config => {
config
.plugin('minify')
.use(BabiliWebpackPlugin);
.use(BabelMinifyWebpackPlugin);
});
```

Expand All @@ -1041,7 +1041,7 @@ neutrino.config
// otherwise set devtool to source-map
neutrino.config
.when(process.env.NODE_ENV === 'production',
config => config.plugin('minify').use(BabiliWebpackPlugin),
config => config.plugin('minify').use(BabelMinifyWebpackPlugin),
config => config.devtool('source-map')
);
```
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -26,7 +26,8 @@
"random": "node -e \"process.stdout.write(require('crypto').randomBytes(8).toString('hex'))\"",
"release": "yarn build && lerna publish --force-publish=*",
"release:preview": "yarn build && lerna publish --force-publish=* --skip-git --skip-npm",
"test": "nyc --reporter lcov ava packages/*/test",
"test": "yarn test:all --no-verbose --match '!*@neutrinojs*'",
"test:all": "nyc --reporter lcov ava --verbose --fail-fast packages/*/test",
"validate:eslintrc:root": "eslint --no-eslintrc --print-config . -c ./.eslintrc.js > /dev/null",
"validate:eslintrc:eslint": "eslint --no-eslintrc --print-config . -c ./packages/eslint/eslintrc.js > /dev/null",
"validate:eslintrc:airbnb": "eslint --no-eslintrc --print-config . -c ./packages/airbnb/eslintrc.js > /dev/null",
Expand Down