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

Commit

Permalink
Upgrading webpack-chain to v3.1 (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
eliperelman committed Mar 30, 2017
1 parent 9871634 commit d009882
Show file tree
Hide file tree
Showing 9 changed files with 247 additions and 250 deletions.
25 changes: 8 additions & 17 deletions packages/neutrino-middleware-compile-loader/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
module.exports = ({ config }, options) => {
const rule = config.module
.rule('compile')
.test(options.test || /\.jsx?$/)
.use('babel')
.loader(require.resolve('babel-loader'))
.options(options.babel)
.end();

if (options.include) {
rule.include.merge(options.include);
}

if (options.exclude) {
rule.exclude.merge(options.exclude);
}
};
module.exports = ({ config }, options) => config.module
.rule('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')
.loader(require.resolve('babel-loader'))
.options(options.babel);
91 changes: 46 additions & 45 deletions packages/neutrino-middleware-eslint/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,14 @@ const merge = require('deepmerge');
const clone = require('lodash.clonedeep');
const { join } = require('path');

const IF_NOT_DEV = process.env.NODE_ENV !== 'development';
const MODULES = join(__dirname, 'node_modules');

module.exports = (neutrino, options) => {
const { config } = neutrino;
const lint = config.module.rule('lint');

config.resolve.modules.add(MODULES);
config.resolveLoader.modules.add(MODULES);

lint
.test(options.test || /\.(js|jsx)$/)
.pre()
.use('eslint')
.loader(require.resolve('eslint-loader'))
.options(merge({
failOnError: IF_NOT_DEV,
emitWarning: IF_NOT_DEV,
emitError: IF_NOT_DEV,
cwd: neutrino.options.root,
useEslintrc: false,
root: true,
plugins: ['babel'],
baseConfig: {},
envs: ['es6'],
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2017,
sourceType: 'module',
ecmaFeatures: {
objectLiteralDuplicateProperties: false,
generators: true,
impliedStrict: true
}
},
settings: {},
globals: ['process'],
rules: {}
}, options.eslint || {}));

if (options.include) {
lint.include.merge(options.include);
}

if (options.exclude) {
lint.exclude.merge(options.exclude);
}
const isNotDev = process.env.NODE_ENV !== 'development';

// eslint-disable-next-line no-param-reassign
neutrino.eslintrc = () => {
const options = clone(config.module.rule('lint').use('eslint').get('options'));
const options = clone(neutrino.config.module.rule('lint').use('eslint').get('options'));

options.extends = options.baseConfig.extends;
options.useEslintrc = true;
Expand All @@ -62,4 +19,48 @@ module.exports = (neutrino, options) => {

return options;
};

neutrino.config
.resolve
.modules
.add(MODULES)
.end()
.end()
.resolveLoader
.modules
.add(MODULES)
.end()
.end()
.module
.rule('lint')
.test(options.test || /\.(js|jsx)$/)
.pre()
.when(options.include, rule => rule.include.merge(options.include))
.when(options.exclude, rule => rule.exclude.merge(options.exclude))
.use('eslint')
.loader(require.resolve('eslint-loader'))
.options(merge({
failOnError: isNotDev,
emitWarning: isNotDev,
emitError: isNotDev,
cwd: neutrino.options.root,
useEslintrc: false,
root: true,
plugins: ['babel'],
baseConfig: {},
envs: ['es6'],
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2017,
sourceType: 'module',
ecmaFeatures: {
objectLiteralDuplicateProperties: false,
generators: true,
impliedStrict: true
}
},
settings: {},
globals: ['process'],
rules: {}
}, options.eslint || {}));
};
9 changes: 3 additions & 6 deletions packages/neutrino-preset-airbnb-base/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ module.exports = (neutrino, options) => {
}
}, options));

if (!options.include && !options.exclude) {
neutrino.config.module
.rule('lint')
.include
.add(neutrino.options.source);
}
neutrino.config.module.rule('lint')
.when(!options.include && !options.exclude,
rule => rule.include.add(neutrino.options.source));
};
7 changes: 3 additions & 4 deletions packages/neutrino-preset-jest/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@ module.exports = (neutrino) => {
}
});

if (neutrino.config.module.rules.has('lint')) {
neutrino.use(loaderMerge('lint', 'eslint'), {
neutrino.config.when(neutrino.config.module.rules.has('lint'), () => neutrino
.use(loaderMerge('lint', 'eslint'), {
plugins: ['jest'],
envs: ['jest']
});
}
}));

const options = normalizeJestOptions(jestOptions, neutrino.config, args);
const configFile = join(tmpdir(), 'config.json');
Expand Down
131 changes: 64 additions & 67 deletions packages/neutrino-preset-node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const { path } = require('ramda');
const MODULES = join(__dirname, 'node_modules');

module.exports = (neutrino) => {
const { config } = neutrino;
let pkg = {};

/* eslint-disable global-require, no-empty */
Expand Down Expand Up @@ -46,8 +45,14 @@ module.exports = (neutrino) => {
}
});

config.performance.hints(false);
config
const hasSourceMap = (pkg.dependencies && 'source-map-support' in pkg.dependencies) ||
(pkg.devDependencies && 'source-map-support' in pkg.devDependencies);

neutrino.config
.when(hasSourceMap, () => neutrino.use(banner))
.performance
.hints(false)
.end()
.target('node')
.node
.set('__filename', false)
Expand Down Expand Up @@ -79,68 +84,60 @@ module.exports = (neutrino) => {
.resolveLoader
.modules
.add(neutrino.options.node_modules)
.add(MODULES);

const hasSourceMap = (pkg.dependencies && 'source-map-support' in pkg.dependencies) ||
(pkg.devDependencies && 'source-map-support' in pkg.devDependencies);

if (hasSourceMap) {
neutrino.use(banner);
}

if (process.env.NODE_ENV !== 'development') {
neutrino.use(clean, { paths: [neutrino.options.output] });
neutrino.use(copy, {
patterns: [{ context: neutrino.options.source, from: '**/*' }],
options: { ignore: ['*.js*'] }
});
} else {
config.devtool('inline-sourcemap');
config.entry('index').add('webpack/hot/poll?1000');
config.output.devtoolModuleFilenameTemplate('[absolute-resource-path]');
neutrino.use(hot);
neutrino.use(startServer, neutrino.options.entry);
}

if (config.module.rules.has('lint')) {
neutrino.use(loaderMerge('lint', 'eslint'), {
envs: ['node'],
rules: {
// enforce return after a callback
'callback-return': 'off',

// require all requires be top-level
// http://eslint.org/docs/rules/global-require
'global-require': 'error',

// enforces error handling in callbacks (node environment)
'handle-callback-err': 'off',

// Allow console in Node.js
'no-console': 'off',

// disallow mixing regular variable and require declarations
'no-mixed-requires': ['off', false],

// disallow use of new operator with the require function
'no-new-require': 'error',

// disallow string concatenation with __dirname and __filename
// http://eslint.org/docs/rules/no-path-concat
'no-path-concat': 'error',

// disallow use of process.env
'no-process-env': 'off',

// disallow process.exit()
'no-process-exit': 'off',

// restrict usage of specified node modules
'no-restricted-modules': 'off',

// disallow use of synchronous methods (off by default)
'no-sync': 'off'
}
});
}
.add(MODULES)
.end()
.end()
.when(process.env.NODE_ENV !== 'development', () => {
neutrino.use(clean, { paths: [neutrino.options.output] });
neutrino.use(copy, {
patterns: [{ context: neutrino.options.source, from: '**/*' }],
options: { ignore: ['*.js*'] }
});
}, (config) => {
config.devtool('inline-sourcemap');
config.entry('index').add('webpack/hot/poll?1000');
config.output.devtoolModuleFilenameTemplate('[absolute-resource-path]');
neutrino.use(hot);
neutrino.use(startServer, neutrino.options.entry);
})
.when(neutrino.config.module.rules.has('lint'), () => neutrino
.use(loaderMerge('lint', 'eslint'), {
envs: ['node'],
rules: {
// enforce return after a callback
'callback-return': 'off',

// require all requires be top-level
// http://eslint.org/docs/rules/global-require
'global-require': 'error',

// enforces error handling in callbacks (node environment)
'handle-callback-err': 'off',

// Allow console in Node.js
'no-console': 'off',

// disallow mixing regular variable and require declarations
'no-mixed-requires': ['off', false],

// disallow use of new operator with the require function
'no-new-require': 'error',

// disallow string concatenation with __dirname and __filename
// http://eslint.org/docs/rules/no-path-concat
'no-path-concat': 'error',

// disallow use of process.env
'no-process-env': 'off',

// disallow process.exit()
'no-process-exit': 'off',

// restrict usage of specified node modules
'no-restricted-modules': 'off',

// disallow use of synchronous methods (off by default)
'no-sync': 'off'
}
}));
};

0 comments on commit d009882

Please sign in to comment.