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

Commit

Permalink
Allow middleware to be reused by allowing option for usage IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
eliperelman committed Sep 26, 2017
1 parent f91373d commit 0f037d8
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/neutrino-middleware-banner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { BannerPlugin } = require('webpack');
const merge = require('deepmerge');

module.exports = ({ config }, options = {}) => config
.plugin('banner')
.plugin(options.pluginId || 'banner')
.use(BannerPlugin, [
merge({
banner: 'require(\'source-map-support\').install();',
Expand Down
2 changes: 1 addition & 1 deletion packages/neutrino-middleware-clean/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ module.exports = (neutrino, options = {}) => {
const { paths, root } = merge({ paths: [], root: neutrino.options.root }, options);

neutrino.config
.plugin('clean')
.plugin(options.pluginId || 'clean')
.use(CleanPlugin, [paths, { root, verbose: false }]);
};
4 changes: 2 additions & 2 deletions packages/neutrino-middleware-compile-loader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ const merge = require('deepmerge');
const babelMerge = require('babel-merge');

module.exports = ({ config }, options = {}) => config.module
.rule('compile')
.rule(options.ruleId || 'compile')
.test(options.test || /\.jsx?$/)
.when(options.include, rule => rule.include.merge(options.include))
.when(options.exclude, rule => rule.exclude.merge(options.exclude))
.use('babel')
.use(options.useId || 'babel')
.loader(require.resolve('babel-loader'))
.options(merge({ cacheDirectory: true }, options.babel || {}));

Expand Down
2 changes: 1 addition & 1 deletion packages/neutrino-middleware-copy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ module.exports = ({ config }, opts = {}) => {
const { patterns, options } = merge({ patterns: [], options: {} }, opts);

config
.plugin('copy')
.plugin(options.pluginId || 'copy')
.use(CopyPlugin, [patterns, options]);
};
2 changes: 1 addition & 1 deletion packages/neutrino-middleware-html-template/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const template = require('html-webpack-template');
const merge = require('deepmerge');

module.exports = ({ config }, options = {}) => config
.plugin('html')
.plugin(options.pluginId || 'html')
.use(HtmlPlugin, [
merge({
template,
Expand Down
2 changes: 1 addition & 1 deletion packages/neutrino-middleware-pwa/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = (neutrino, options = {}) => neutrino.config
.entry('index')
.add(require.resolve('./pwa'))
.end()
.plugin('pwa')
.plugin(options.pluginId || 'pwa')
.use(OfflinePlugin, [
merge({
ServiceWorker: {
Expand Down
2 changes: 1 addition & 1 deletion packages/neutrino-middleware-start-server/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const StartServerPlugin = require('start-server-webpack-plugin');

module.exports = (neutrino, options = {}) => neutrino.config
.plugin('start-server')
.plugin(options.pluginId || 'start-server')
.use(StartServerPlugin, [{
name: options.name,
nodeArgs: neutrino.options.debug ? ['--inspect'] : []
Expand Down
6 changes: 3 additions & 3 deletions packages/neutrino-middleware-style-loader/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module.exports = ({ config }, options = {}) => config.module
.rule('style')
.rule(options.ruleId || 'style')
.test(/\.css$/)
.use('style')
.use(options.styleUseId || 'style')
.loader(require.resolve('style-loader'))
.when(options.style, use => use.options(options.style))
.end()
.use('css')
.use(options.cssUseId || 'css')
.loader(require.resolve('css-loader'))
.when(options.css, use => use.options(options.css));
3 changes: 2 additions & 1 deletion packages/neutrino-preset-web/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const MODULES = join(__dirname, 'node_modules');

module.exports = (neutrino, opts = {}) => {
const options = merge({
env: [],
hot: true,
html: {},
devServer: {
Expand Down Expand Up @@ -66,7 +67,7 @@ module.exports = (neutrino, opts = {}) => {
);
}

neutrino.use(env);
neutrino.use(env, options.env);
neutrino.use(htmlLoader);
neutrino.use(styleLoader);
neutrino.use(fontLoader);
Expand Down

0 comments on commit 0f037d8

Please sign in to comment.