Browse Source

Upgrading webpack-chain to v3.1 (#157)

v6-dev
Eli Perelman 8 years ago
committed by GitHub
parent
commit
d009882e6d
  1. 17
      packages/neutrino-middleware-compile-loader/index.js
  2. 61
      packages/neutrino-middleware-eslint/index.js
  3. 9
      packages/neutrino-preset-airbnb-base/index.js
  4. 7
      packages/neutrino-preset-jest/src/index.js
  5. 37
      packages/neutrino-preset-node/index.js
  6. 42
      packages/neutrino-preset-react/index.js
  7. 60
      packages/neutrino-preset-web/index.js
  8. 2
      packages/neutrino/package.json
  9. 6
      packages/neutrino/yarn.lock

17
packages/neutrino-middleware-compile-loader/index.js

@ -1,17 +1,8 @@
module.exports = ({ config }, options) => {
const rule = config.module
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)
.end();
if (options.include) {
rule.include.merge(options.include);
}
if (options.exclude) {
rule.exclude.merge(options.exclude);
}
};
.options(options.babel);

61
packages/neutrino-middleware-eslint/index.js

@ -2,25 +2,47 @@ 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');
const isNotDev = process.env.NODE_ENV !== 'development';
config.resolve.modules.add(MODULES);
config.resolveLoader.modules.add(MODULES);
// eslint-disable-next-line no-param-reassign
neutrino.eslintrc = () => {
const options = clone(neutrino.config.module.rule('lint').use('eslint').get('options'));
options.extends = options.baseConfig.extends;
options.useEslintrc = true;
options.env = options.envs.reduce((env, key) => Object.assign(env, { [key]: true }), {});
options.globals = options.globals.reduce((globals, key) => Object.assign(globals, { [key]: true }), {});
['envs', 'baseConfig', 'failOnError', 'emitWarning', 'emitError'].map(method => delete options[method]);
return options;
};
lint
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: IF_NOT_DEV,
emitWarning: IF_NOT_DEV,
emitError: IF_NOT_DEV,
failOnError: isNotDev,
emitWarning: isNotDev,
emitError: isNotDev,
cwd: neutrino.options.root,
useEslintrc: false,
root: true,
@ -41,25 +63,4 @@ module.exports = (neutrino, options) => {
globals: ['process'],
rules: {}
}, options.eslint || {}));
if (options.include) {
lint.include.merge(options.include);
}
if (options.exclude) {
lint.exclude.merge(options.exclude);
}
// eslint-disable-next-line no-param-reassign
neutrino.eslintrc = () => {
const options = clone(config.module.rule('lint').use('eslint').get('options'));
options.extends = options.baseConfig.extends;
options.useEslintrc = true;
options.env = options.envs.reduce((env, key) => Object.assign(env, { [key]: true }), {});
options.globals = options.globals.reduce((globals, key) => Object.assign(globals, { [key]: true }), {});
['envs', 'baseConfig', 'failOnError', 'emitWarning', 'emitError'].map(method => delete options[method]);
return options;
};
};

9
packages/neutrino-preset-airbnb-base/index.js

@ -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
packages/neutrino-preset-jest/src/index.js

@ -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');

37
packages/neutrino-preset-node/index.js

@ -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 */
@ -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)
@ -79,31 +84,24 @@ 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') {
.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*'] }
});
} else {
}, (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);
}
if (config.module.rules.has('lint')) {
neutrino.use(loaderMerge('lint', 'eslint'), {
})
.when(neutrino.config.module.rules.has('lint'), () => neutrino
.use(loaderMerge('lint', 'eslint'), {
envs: ['node'],
rules: {
// enforce return after a callback
@ -141,6 +139,5 @@ module.exports = (neutrino) => {
// disallow use of synchronous methods (off by default)
'no-sync': 'off'
}
});
}
}));
};

42
packages/neutrino-preset-react/index.js

@ -5,8 +5,6 @@ const { join } = require('path');
const MODULES = join(__dirname, 'node_modules');
module.exports = (neutrino) => {
const { config } = neutrino;
neutrino.use(web);
neutrino.use(loaderMerge('compile', 'babel'), {
presets: [require.resolve('babel-preset-react')],
@ -18,24 +16,33 @@ module.exports = (neutrino) => {
}
});
config.resolve.modules.add(MODULES);
config.resolve.extensions.add('.jsx');
config.resolve.alias.set('react-native', 'react-native-web');
config.resolveLoader.modules.add(MODULES);
config.externals({
neutrino.config
.resolve
.modules
.add(MODULES)
.end()
.extensions
.add('.jsx')
.end()
.alias
.set('react-native', 'react-native-web')
.end()
.end()
.resolveLoader
.modules
.add(MODULES)
.end()
.end()
.externals({
'react/addons': true,
'react/lib/ExecutionEnvironment': true,
'react/lib/ReactContext': 'window'
});
if (process.env.NODE_ENV === 'development') {
config
})
.when(process.env.NODE_ENV === 'development', config => config
.entry('index')
.prepend(require.resolve('react-hot-loader/patch'));
}
if (config.module.rules.has('lint')) {
neutrino.use(loaderMerge('lint', 'eslint'), {
.prepend(require.resolve('react-hot-loader/patch')))
.when(neutrino.config.module.rules.has('lint'), () => neutrino
.use(loaderMerge('lint', 'eslint'), {
plugins: ['react'],
baseConfig: {
extends: ['plugin:react/recommended']
@ -64,6 +71,5 @@ module.exports = (neutrino) => {
]
}]
}
});
}
}));
};

60
packages/neutrino-preset-web/index.js

@ -42,8 +42,6 @@ function devServer({ config }, options) {
}
module.exports = (neutrino) => {
const { config } = neutrino;
if (!path(['options', 'compile', 'targets', 'browsers'], neutrino)) {
Object.assign(neutrino.options, {
compile: {
@ -83,28 +81,38 @@ module.exports = (neutrino) => {
}
});
if (process.env.NODE_ENV !== 'test') {
neutrino.use(chunk);
}
config
neutrino.config
.when(process.env.NODE_ENV !== 'test', () => neutrino.use(chunk))
.target('web')
.context(neutrino.options.root)
.entry('index')
.add(require.resolve('babel-polyfill'))
.add(neutrino.options.entry);
config.output
.add(neutrino.options.entry)
.end()
.output
.path(neutrino.options.output)
.publicPath('./')
.filename('[name].bundle.js')
.chunkFilename('[id].[chunkhash].js');
config.resolve.modules.add('node_modules').add(neutrino.options.node_modules).add(MODULES);
config.resolve.extensions.add('.js').add('.json');
config.resolveLoader.modules.add(neutrino.options.node_modules).add(MODULES);
config.node
.chunkFilename('[id].[chunkhash].js')
.end()
.resolve
.modules
.add('node_modules')
.add(neutrino.options.node_modules)
.add(MODULES)
.end()
.extensions
.add('.js')
.add('.json')
.end()
.end()
.resolveLoader
.modules
.add(neutrino.options.node_modules)
.add(MODULES)
.end()
.end()
.node
.set('console', false)
.set('global', true)
.set('process', true)
@ -113,16 +121,14 @@ module.exports = (neutrino) => {
.set('__dirname', 'mock')
.set('setImmediate', true)
.set('fs', 'empty')
.set('tls', 'empty');
if (config.module.rules.has('lint')) {
neutrino.use(loaderMerge('lint', 'eslint'), {
.set('tls', 'empty')
.end()
.when(neutrino.config.module.rules.has('lint'), () => neutrino
.use(loaderMerge('lint', 'eslint'), {
globals: ['Buffer'],
envs: ['browser', 'commonjs']
});
}
if (process.env.NODE_ENV === 'development') {
}))
.when(process.env.NODE_ENV === 'development', (config) => {
const protocol = process.env.HTTPS ? 'https' : 'http';
const host = process.env.HOST || pathOr('localhost', ['options', 'config', 'devServer', 'host'], neutrino);
const port = process.env.PORT || pathOr(5000, ['options', 'config', 'devServer', 'port'], neutrino);
@ -140,7 +146,7 @@ module.exports = (neutrino) => {
.entry('index')
.add(`webpack-dev-server/client?${protocol}://${host}:${port}/`)
.add('webpack/hot/dev-server');
} else {
}, (config) => {
neutrino.use(clean, { paths: [neutrino.options.output] });
neutrino.use(minify);
neutrino.use(copy, {
@ -148,5 +154,5 @@ module.exports = (neutrino) => {
options: { ignore: ['*.js*'] }
});
config.output.filename('[name].[chunkhash].bundle.js');
}
});
};

2
packages/neutrino/package.json

@ -34,7 +34,7 @@
"ramda": "^0.23.0",
"ramda-fantasy": "^0.7.0",
"webpack": "^2.3.1",
"webpack-chain": "^3.0.0",
"webpack-chain": "^3.1.0",
"webpack-dev-server": "^2.4.2",
"yargs": "^7.0.2"
},

6
packages/neutrino/yarn.lock

@ -2218,9 +2218,9 @@ wbuf@^1.1.0, wbuf@^1.4.0:
dependencies:
minimalistic-assert "^1.0.0"
webpack-chain@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/webpack-chain/-/webpack-chain-3.0.0.tgz#20d0b92e84cb294035e1fa03ce2fb8805cce51b6"
webpack-chain@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/webpack-chain/-/webpack-chain-3.1.0.tgz#53e82857624d48794443238db99248e598550e03"
dependencies:
deepmerge "^1.3.2"

Loading…
Cancel
Save