You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
3.5 KiB
127 lines
3.5 KiB
const banner = require('neutrino-middleware-banner');
|
|
const compile = require('neutrino-middleware-compile-loader');
|
|
const copy = require('neutrino-middleware-copy');
|
|
const progress = require('neutrino-middleware-progress');
|
|
const clean = require('neutrino-middleware-clean');
|
|
const nodeExternals = require('webpack-node-externals');
|
|
const { join } = require('path');
|
|
const merge = require('deepmerge');
|
|
|
|
const CWD = process.cwd();
|
|
const SRC = join(CWD, 'src');
|
|
const BUILD = join(CWD, 'build');
|
|
const TEST = join(CWD, 'test');
|
|
const PROJECT_MODULES = join(CWD, 'node_modules');
|
|
const MODULES = join(__dirname, 'node_modules');
|
|
const PKG = require(join(CWD, 'package.json'));
|
|
|
|
module.exports = (config, neutrino) => {
|
|
neutrino.use(compile({
|
|
include: [SRC, TEST],
|
|
babel: {
|
|
presets: [
|
|
[require.resolve('babel-preset-env'), {
|
|
modules: false,
|
|
targets: {
|
|
node: 6.9
|
|
}
|
|
}]
|
|
]
|
|
}
|
|
}));
|
|
|
|
config.options.set('performance', { hints: false });
|
|
config
|
|
.target('node')
|
|
.node
|
|
.set('__filename', false)
|
|
.set('__dirname', false)
|
|
.end()
|
|
.devtool('source-map')
|
|
.externals([nodeExternals()])
|
|
.context(CWD)
|
|
.entry('index')
|
|
.add(join(SRC, 'index.js'))
|
|
.end()
|
|
.output
|
|
.path(BUILD)
|
|
.filename('[name].js')
|
|
.libraryTarget('commonjs2')
|
|
.chunkFilename('[id].[chunkhash].js')
|
|
.end()
|
|
.resolve
|
|
.modules
|
|
.add(PROJECT_MODULES)
|
|
.add(MODULES)
|
|
.end()
|
|
.extensions
|
|
.add('.js')
|
|
.add('json')
|
|
.end()
|
|
.end()
|
|
.resolveLoader
|
|
.modules
|
|
.add(PROJECT_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([
|
|
copy({ patterns: [{ context: SRC, from: `**/*` }], options: { ignore: ['*.js*'] } }),
|
|
progress(),
|
|
clean({ paths: [BUILD] })
|
|
])
|
|
}
|
|
|
|
if (config.module.rules.has('lint')) {
|
|
config.module
|
|
.rule('lint')
|
|
.loader('eslint', props => merge(props, {
|
|
options: {
|
|
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'
|
|
}
|
|
}
|
|
}));
|
|
}
|
|
};
|
|
|