Browse Source

Trying out use(loader, options)

v5.0.0-beta
Eli Perelman 8 years ago
parent
commit
73ef503d15
  1. 2
      packages/neutrino-middleware-banner/index.js
  2. 2
      packages/neutrino-middleware-chunk/index.js
  3. 2
      packages/neutrino-middleware-clean/index.js
  4. 4
      packages/neutrino-middleware-compile-loader/index.js
  5. 2
      packages/neutrino-middleware-copy/index.js
  6. 4
      packages/neutrino-middleware-env/index.js
  7. 4
      packages/neutrino-middleware-eslint/index.js
  8. 2
      packages/neutrino-middleware-font-loader/index.js
  9. 2
      packages/neutrino-middleware-hot/index.js
  10. 2
      packages/neutrino-middleware-html-loader/index.js
  11. 2
      packages/neutrino-middleware-html-template/index.js
  12. 2
      packages/neutrino-middleware-image-loader/index.js
  13. 5
      packages/neutrino-middleware-loader-merge/index.js
  14. 21
      packages/neutrino-middleware-loader-merge/package.json
  15. 7
      packages/neutrino-middleware-loader-merge/yarn.lock
  16. 2
      packages/neutrino-middleware-minify/index.js
  17. 2
      packages/neutrino-middleware-progress/index.js
  18. 2
      packages/neutrino-middleware-style-loader/index.js
  19. 6
      packages/neutrino-preset-airbnb-base/index.js
  20. 3
      packages/neutrino-preset-jest/package.json
  21. 40
      packages/neutrino-preset-jest/src/index.js
  22. 4
      packages/neutrino-preset-karma/index.js
  23. 3
      packages/neutrino-preset-mocha/package.json
  24. 27
      packages/neutrino-preset-mocha/src/index.js
  25. 85
      packages/neutrino-preset-node/index.js
  26. 8
      packages/neutrino-preset-node/package.json
  27. 4
      packages/neutrino-preset-node/yarn.lock
  28. 97
      packages/neutrino-preset-react/index.js
  29. 6
      packages/neutrino-preset-react/package.json
  30. 4210
      packages/neutrino-preset-react/yarn.lock
  31. 105
      packages/neutrino-preset-web/index.js
  32. 2
      packages/neutrino-preset-web/package.json
  33. 4
      packages/neutrino-preset-web/yarn.lock
  34. 8
      packages/neutrino/src/neutrino.js

2
packages/neutrino-middleware-banner/index.js

@ -1,7 +1,7 @@
const { BannerPlugin } = require('webpack');
const merge = require('deepmerge');
module.exports = (options = {}) => config => config
module.exports = ({ config }, options) => config
.plugin('banner')
.use(BannerPlugin, merge({
banner: `require('source-map-support').install();`,

2
packages/neutrino-middleware-chunk/index.js

@ -1,7 +1,7 @@
const { CommonsChunkPlugin } = require('webpack').optimize;
const merge = require('deepmerge');
module.exports = (options = {}) => config => config
module.exports = ({ config }, options) => config
.plugin('chunk')
.use(CommonsChunkPlugin, merge({
minChunks: Infinity,

2
packages/neutrino-middleware-clean/index.js

@ -1,7 +1,7 @@
const CleanPlugin = require('clean-webpack-plugin');
const merge = require('deepmerge');
module.exports = (options = {}) => config => {
module.exports = ({ config }, options) => {
const { paths, root } = merge({ paths: [], root: process.cwd() }, options);
config

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

@ -1,5 +1,5 @@
module.exports = options => config => config.module
module.exports = ({ config }, options) => config.module
.rule('compile')
.test(/\.js$/)
.test(/\.jsx?$/)
.include(...options.include)
.loader('babel', require.resolve('babel-loader'), options.babel);

2
packages/neutrino-middleware-copy/index.js

@ -1,7 +1,7 @@
const CopyPlugin = require('copy-webpack-plugin');
const merge = require('deepmerge');
module.exports = (options = {}) => config => {
module.exports = ({ config }, options) => {
const opts = merge({ patterns: [], options: {} }, options);
config

4
packages/neutrino-middleware-env/index.js

@ -1,5 +1,5 @@
const { EnvironmentPlugin } = require('webpack');
module.exports = (envs = []) => config => config
module.exports = ({ config }, envs = []) => config
.plugin('env')
.use(EnvironmentPlugin, ['NODE_ENV', ...envs]);
.use(EnvironmentPlugin, ['NODE_ENV', ...(Array.isArray(envs) ? envs : [])]);

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

@ -5,7 +5,9 @@ const { join } = require('path');
const IF_NOT_DEV = process.env.NODE_ENV !== 'development';
const MODULES = join(__dirname, 'node_modules');
module.exports = options => (config, neutrino) => {
module.exports = (neutrino, options) => {
const { config } = neutrino;
config.resolve.modules.add(MODULES);
config.resolveLoader.modules.add(MODULES);
config.module

2
packages/neutrino-middleware-font-loader/index.js

@ -1,6 +1,6 @@
const merge = require('deepmerge');
module.exports = (options = {}) => config => {
module.exports = ({ config }, options) => {
const { limit } = merge({ limit: '10000' }, options);
const urlLoader = require.resolve('url-loader');
const fileLoader = require.resolve('file-loader');

2
packages/neutrino-middleware-hot/index.js

@ -1,3 +1,3 @@
const { HotModuleReplacementPlugin } = require('webpack');
module.exports = () => config => config.plugin('hot').use(HotModuleReplacementPlugin);
module.exports = ({ config }) => config.plugin('hot').use(HotModuleReplacementPlugin);

2
packages/neutrino-middleware-html-loader/index.js

@ -1,4 +1,4 @@
module.exports = () => config => config.module
module.exports = ({ config }) => config.module
.rule('html')
.test(/\.html$/)
.loader('file', require.resolve('file-loader'), { name: '[name].[ext]' });

2
packages/neutrino-middleware-html-template/index.js

@ -2,7 +2,7 @@ const HtmlPlugin = require('html-webpack-plugin');
const template = require('html-webpack-template');
const merge = require('deepmerge');
module.exports = (options = {}) => config => config
module.exports = ({ config }, options) => config
.plugin('html')
.use(HtmlPlugin, merge({
template,

2
packages/neutrino-middleware-image-loader/index.js

@ -1,6 +1,6 @@
const merge = require('deepmerge');
module.exports = (options = {}) => config => {
module.exports = ({ config }, options) => {
const { limit } = merge({ limit: 8192 }, options);
const urlLoader = require.resolve('url-loader');

5
packages/neutrino-middleware-loader-merge/index.js

@ -0,0 +1,5 @@
const merge = require('deepmerge');
module.exports = (ruleId, loaderId) => ({ config }, options) => config.module
.rule(ruleId)
.loader(loaderId, props => merge(props, { options }));

21
packages/neutrino-middleware-loader-merge/package.json

@ -0,0 +1,21 @@
{
"name": "neutrino-middleware-loader-merge",
"version": "5.0.0",
"description": "Neutrino middleware for merging options into existing ruleset loader options",
"main": "index.js",
"keywords": [
"neutrino",
"neutrino-middleware",
"rule",
"loader",
"merge"
],
"author": "Eli Perelman <eli@eliperelman.com>",
"license": "MPL-2.0",
"repository": "mozilla-neutrino/neutrino-dev",
"homepage": "https://neutrino.js.org",
"bugs": "https://github.com/mozilla-neutrino/neutrino-dev/issues",
"dependencies": {
"deepmerge": "^1.3.2"
}
}

7
packages/neutrino-middleware-loader-merge/yarn.lock

@ -0,0 +1,7 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
deepmerge@^1.3.2:
version "1.3.2"
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-1.3.2.tgz#1663691629d4dbfe364fa12a2a4f0aa86aa3a050"

2
packages/neutrino-middleware-minify/index.js

@ -1,3 +1,3 @@
const BabiliPlugin = require('babili-webpack-plugin');
module.exports = () => config => config.plugin('minify').use(BabiliPlugin);
module.exports = ({ config }) => config.plugin('minify').use(BabiliPlugin);

2
packages/neutrino-middleware-progress/index.js

@ -1,3 +1,3 @@
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
module.exports = () => config => config.plugin('progress').use(ProgressBarPlugin);
module.exports = ({ config }) => config.plugin('progress').use(ProgressBarPlugin);

2
packages/neutrino-middleware-style-loader/index.js

@ -1,4 +1,4 @@
module.exports = () => config => config.module
module.exports = ({ config }) => config.module
.rule('style')
.test(/\.css$/)
.loader('style', require.resolve('style-loader'))

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

@ -1,7 +1,7 @@
const lint = require('neutrino-middleware-eslint');
const { join } = require('path');
module.exports = (config, neutrino) => neutrino.use(lint({
module.exports = neutrino => neutrino.use(lint, {
include: [join(process.cwd(), 'SRC')],
eslint: {
baseConfig: {
@ -15,7 +15,7 @@ module.exports = (config, neutrino) => neutrino.use(lint({
'object-curly-spacing': 'off',
// require a capital letter for constructors
'babel/new-cap': ['error', {newIsCap: true}],
'babel/new-cap': ['error', { newIsCap: true }],
// require padding inside curly braces
'babel/object-curly-spacing': ['error', 'always'],
@ -24,4 +24,4 @@ module.exports = (config, neutrino) => neutrino.use(lint({
'babel/no-await-in-loop': 'error'
}
}
}));
});

3
packages/neutrino-preset-jest/package.json

@ -21,7 +21,8 @@
"eslint-plugin-jest": "^19.0.1",
"jest": "^19.0.2",
"jest-cli": "^19.0.2",
"lodash.clonedeep": "^4.5.0"
"lodash.clonedeep": "^4.5.0",
"neutrino-middleware-loader-merge": "^5.0.0"
},
"peerDependencies": {
"neutrino": "^5.0.0"

40
packages/neutrino-preset-jest/src/index.js

@ -4,6 +4,7 @@ const path = require('path');
const merge = require('deepmerge');
const os = require('os');
const clone = require('lodash.clonedeep');
const loaderMerge = require('neutrino-middleware-loader-merge');
const pkg = require(path.join(process.cwd(), 'package.json'));
function normalizeJestOptions(jestOptions, config, args) {
@ -33,15 +34,7 @@ function normalizeJestOptions(jestOptions, config, args) {
return options;
}
const compile = ({ babel }) => config => config.module
.rule('compile')
.loader('babel', props => merge(props, { options: babel }));
const lint = ({ eslint }) => config => config.module
.rule('lint')
.loader('eslint', props => merge(props, { options: eslint }));
module.exports = (config, neutrino) => {
module.exports = neutrino => {
const jestOptions = merge.all([
{
bail: true,
@ -57,26 +50,25 @@ module.exports = (config, neutrino) => {
'\\.(css|less|sass)$': require.resolve('./style-mock')
}
},
pkg.jest,
neutrino.options.jest
pkg.jest || {},
neutrino.options.jest || {}
]);
neutrino.use([
compile({
babel: {
env: {
test: {
retainLines: true,
presets: [require.resolve('babel-preset-jest')],
plugins: [require.resolve('babel-plugin-transform-es2015-modules-commonjs')]
}
}
neutrino.use(loaderMerge('compile', 'babel'), {
env: {
test: {
retainLines: true,
presets: [require.resolve('babel-preset-jest')],
plugins: [require.resolve('babel-plugin-transform-es2015-modules-commonjs')]
}
})
]);
}
});
if (neutrino.config.module.rules.has('lint')) {
neutrino.use(lint({ eslint: { plugins: ['jest'], envs: ['jest'] } }));
neutrino.use(loaderMerge('lint', 'eslint'), {
plugins: ['jest'],
envs: ['jest']
});
}
neutrino.on('test', args => {

4
packages/neutrino-preset-karma/index.js

@ -1,7 +1,7 @@
const { Server } = require('karma');
const merge = require('deepmerge');
module.exports = (config, neutrino) => {
module.exports = neutrino => {
const defaults = {
plugins: [
require.resolve('karma-webpack'),
@ -38,7 +38,7 @@ module.exports = (config, neutrino) => {
neutrino.on('test', ({ files, watch }) => {
const karma = merge.all([
defaults,
neutrino.options.karma,
neutrino.options.karma || {},
{
singleRun: !watch,
autoWatch: watch,

3
packages/neutrino-preset-mocha/package.json

@ -16,7 +16,8 @@
"babel-register": "^6.23.0",
"change-case": "^3.0.1",
"deepmerge": "^1.3.2",
"mocha": "^3.2.0"
"mocha": "^3.2.0",
"neutrino-middleware-loader-merge": "^5.0.0"
},
"peerDependencies": {
"neutrino": "^5.0.0"

27
packages/neutrino-preset-mocha/src/index.js

@ -1,27 +1,18 @@
const mocha = require('./mocha');
const merge = require('deepmerge');
const loaderMerge = require('neutrino-middleware-loader-merge');
module.exports = (config, neutrino) => {
const defaults = {
reporter: 'spec',
ui: 'tdd',
bail: true
};
config.module
.rule('compile')
.loader('babel', props => merge(props, {
options: {
env: {
test: {
plugins: [require.resolve('babel-plugin-transform-es2015-modules-commonjs')]
}
}
module.exports = neutrino => {
neutrino.use(loaderMerge('compile', 'babel'), {
env: {
test: {
plugins: [require.resolve('babel-plugin-transform-es2015-modules-commonjs')]
}
}));
}
});
neutrino.on('test', ({ files }) => mocha(
merge(defaults, neutrino.options.mocha),
merge({ reporter: 'spec', ui: 'tdd', bail: true }, neutrino.options.mocha || {}),
neutrino.config.module.rule('compile').loaders.get('babel').options,
files
));

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

@ -3,9 +3,9 @@ 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 loaderMerge = require('neutrino-middleware-loader-merge');
const nodeExternals = require('webpack-node-externals');
const { join } = require('path');
const merge = require('deepmerge');
const CWD = process.cwd();
const SRC = join(CWD, 'src');
@ -15,8 +15,10 @@ 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({
module.exports = neutrino => {
const { config } = neutrino;
neutrino.use(compile, {
include: [SRC, TEST],
babel: {
presets: [
@ -28,7 +30,7 @@ module.exports = (config, neutrino) => {
}]
]
}
}));
});
config.options.set('performance', { hints: false });
config
@ -68,60 +70,57 @@ module.exports = (config, neutrino) => {
(PKG.devDependencies && 'source-map-support' in PKG.devDependencies);
if (hasSourceMap) {
neutrino.use(banner());
neutrino.use(banner);
}
if (process.env.NODE_ENV !== 'development') {
neutrino.use([
copy({ patterns: [{ context: SRC, from: `**/*` }], options: { ignore: ['*.js*'] } }),
progress(),
clean({ paths: [BUILD] })
])
neutrino.use(clean, { paths: [BUILD] });
neutrino.use(progress);
neutrino.use(copy, {
patterns: [{ context: SRC, from: `**/*` }],
options: { ignore: ['*.js*'] }
});
}
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',
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',
// 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',
// enforces error handling in callbacks (node environment)
'handle-callback-err': 'off',
// Allow console in Node.js
'no-console': 'off',
// Allow console in Node.js
'no-console': 'off',
// disallow mixing regular variable and require declarations
'no-mixed-requires': ['off', false],
// 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 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 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 use of process.env
'no-process-env': 'off',
// disallow process.exit()
'no-process-exit': 'off',
// disallow process.exit()
'no-process-exit': 'off',
// restrict usage of specified node modules
'no-restricted-modules': 'off',
// restrict usage of specified node modules
'no-restricted-modules': 'off',
// disallow use of synchronous methods (off by default)
'no-sync': 'off'
}
}
}));
// disallow use of synchronous methods (off by default)
'no-sync': 'off'
}
});
}
};

8
packages/neutrino-preset-node/package.json

@ -16,15 +16,15 @@
"bugs": "https://github.com/mozilla-neutrino/neutrino-dev/issues",
"dependencies": {
"babel-preset-env": "^1.1.10",
"deepmerge": "^1.3.2",
"exports-loader": "^0.6.4",
"imports-loader": "^0.7.1",
"webpack-node-externals": "1.5.4",
"neutrino-middleware-banner": "^5.0.0",
"neutrino-middleware-clean": "^5.0.0",
"neutrino-middleware-compile-loader": "^5.0.0",
"neutrino-middleware-copy": "^5.0.0",
"neutrino-middleware-progress": "^5.0.0",
"neutrino-middleware-clean": "^5.0.0",
"webpack-node-externals": "1.5.4"
"neutrino-middleware-loader-merge": "^5.0.0",
"neutrino-middleware-progress": "^5.0.0"
},
"peerDependencies": {
"neutrino": "^5.0.0"

4
packages/neutrino-preset-node/yarn.lock

@ -447,10 +447,6 @@ debug@^2.2.0:
dependencies:
ms "0.7.1"
deepmerge@^1.3.2:
version "1.3.2"
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-1.3.2.tgz#1663691629d4dbfe364fa12a2a4f0aa86aa3a050"
electron-to-chromium@^1.1.0, electron-to-chromium@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.2.2.tgz#e41bc9488c88e3cfa1e94bde28e8420d7d47c47c"

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

@ -1,11 +1,22 @@
const loaderMerge = require('neutrino-middleware-loader-merge');
const web = require('neutrino-preset-web');
const merge = require('deepmerge');
const { join } = require('path');
const MODULES = join(__dirname, 'node_modules');
module.exports = (config, neutrino) => {
module.exports = neutrino => {
const { config } = neutrino;
neutrino.use(web);
neutrino.use(loaderMerge('compile', 'babel'), {
presets: [require.resolve('babel-preset-react')],
plugins: [require.resolve('babel-plugin-transform-object-rest-spread')],
env: {
development: {
plugins: [require.resolve('react-hot-loader/babel')]
}
}
});
config.resolve.modules.add(MODULES);
config.resolve.extensions.add('.jsx');
@ -18,21 +29,6 @@ module.exports = (config, neutrino) => {
'react/lib/ReactContext': 'window'
});
config.module
.rule('compile')
.test(/\.jsx?$/)
.loader('babel', props => merge(props, {
options: {
presets: [require.resolve('babel-preset-react')],
plugins: [require.resolve('babel-plugin-transform-object-rest-spread')],
env: {
development: {
plugins: [require.resolve('react-hot-loader/babel')]
}
}
}
}));
if (process.env.NODE_ENV === 'development') {
config
.entry('index')
@ -40,44 +36,35 @@ module.exports = (config, neutrino) => {
}
if (config.module.rules.has('lint')) {
config.module
.rule('lint')
.test(/\.jsx?$/)
.loader('eslint', props => merge(props, {
options: {
plugins: ['react'],
baseConfig: {
extends: ['plugin:react/recommended']
},
parserOptions: {
ecmaFeatures: {
experimentalObjectRestSpread: true
}
},
rules: {
'react/prop-types': ['off'],
'jsx-quotes': ['error', 'prefer-double'],
'class-methods-use-this': ['error', {
exceptMethods: [
'render',
'getInitialState',
'getDefaultProps',
'getChildContext',
'componentWillMount',
'componentDidMount',
'componentWillReceiveProps',
'shouldComponentUpdate',
'componentWillUpdate',
'componentDidUpdate',
'componentWillUnmount'
]
}]
}
neutrino.use(loaderMerge('lint', 'eslint'), {
plugins: ['react'],
baseConfig: {
extends: ['plugin:react/recommended']
},
parserOptions: {
ecmaFeatures: {
experimentalObjectRestSpread: true
}
}));
},
rules: {
'react/prop-types': ['off'],
'jsx-quotes': ['error', 'prefer-double'],
'class-methods-use-this': ['error', {
exceptMethods: [
'render',
'getInitialState',
'getDefaultProps',
'getChildContext',
'componentWillMount',
'componentDidMount',
'componentWillReceiveProps',
'shouldComponentUpdate',
'componentWillUpdate',
'componentDidUpdate',
'componentWillUnmount'
]
}]
}
});
}
// console.log(config.module.toConfig());
// console.log(neutrino.getWebpackOptions().module.rules);
// process.exit();
};

6
packages/neutrino-preset-react/package.json

@ -18,10 +18,10 @@
"dependencies": {
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-preset-react": "^6.23.0",
"deepmerge": "^1.3.2",
"eslint-plugin-react": "^6.10.0",
"neutrino-preset-web": "^5.0.0",
"react-hot-loader": "^3.0.0-beta.6"
"react-hot-loader": "^3.0.0-beta.6",
"neutrino-middleware-loader-merge": "^5.0.0",
"neutrino-preset-web": "^5.0.0"
},
"peerDependencies": {
"neutrino": "^5.0.0"

4210
packages/neutrino-preset-react/yarn.lock

File diff suppressed because it is too large

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

@ -11,7 +11,7 @@ const copy = require('neutrino-middleware-copy');
const progress = require('neutrino-middleware-progress');
const clean = require('neutrino-middleware-clean');
const minify = require('neutrino-middleware-minify');
const merge = require('deepmerge');
const loaderMerge = require('neutrino-middleware-loader-merge');
const { join } = require('path');
const CWD = process.cwd();
@ -22,7 +22,7 @@ const PKG = require(join(CWD, 'package.json'));
const PROJECT_MODULES = join(CWD, 'node_modules');
const MODULES = join(__dirname, 'node_modules');
const devServer = (options = {}) => config => config.devServer
const devServer = ({ config }, options) => config.devServer
.host(options.host)
.port(parseInt(options.port))
.https(options.https)
@ -44,40 +44,40 @@ const devServer = (options = {}) => config => config.devServer
warnings: true
});
module.exports = (config, neutrino) => {
neutrino.use([
env(),
htmlLoader(),
styleLoader(),
fontLoader(),
imageLoader(),
htmlTemplate(),
compileLoader({
include: [SRC, TEST],
babel: {
presets: [
[require.resolve('babel-preset-env'), {
modules: false,
useBuiltIns: true,
include: ['transform-regenerator'],
targets: {
browsers: [
'last 2 Chrome versions',
'last 2 Firefox versions',
'last 2 Edge versions',
'last 2 Opera versions',
'last 2 Safari versions',
'last 2 iOS versions'
]
}
}]
]
}
})
]);
module.exports = neutrino => {
const { config } = neutrino;
neutrino.use(env);
neutrino.use(htmlLoader);
neutrino.use(styleLoader);
neutrino.use(fontLoader);
neutrino.use(imageLoader);
neutrino.use(htmlTemplate);
neutrino.use(compileLoader, {
include: [SRC, TEST],
babel: {
presets: [
[require.resolve('babel-preset-env'), {
modules: false,
useBuiltIns: true,
include: ['transform-regenerator'],
targets: {
browsers: [
'last 2 Chrome versions',
'last 2 Firefox versions',
'last 2 Edge versions',
'last 2 Opera versions',
'last 2 Safari versions',
'last 2 iOS versions'
]
}
}]
]
}
});
if (process.env.NODE_ENV !== 'test') {
neutrino.use(chunk());
neutrino.use(chunk);
}
config
@ -108,14 +108,10 @@ module.exports = (config, neutrino) => {
.set('tls', 'empty');
if (config.module.rules.has('lint')) {
config.module
.rule('lint')
.loader('eslint', props => merge(props, {
options: {
globals: ['Buffer'],
envs: ['browser', 'commonjs']
}
}));
neutrino.use(loaderMerge('lint', 'eslint'), {
globals: ['Buffer'],
envs: ['browser', 'commonjs']
});
}
if (process.env.NODE_ENV === 'development') {
@ -127,10 +123,13 @@ module.exports = (config, neutrino) => {
(PKG.neutrino && PKG.neutrino.config && PKG.neutrino.config.devServer && PKG.neutrino.config.devServer.port) ||
5000;
neutrino.use([
devServer({ host, port, https: protocol === 'https', contentBase: SRC }),
hot()
]);
neutrino.use(hot);
neutrino.use(devServer, {
host,
port,
https: protocol === 'https',
contentBase: SRC
});
config
.devtool('eval')
@ -138,13 +137,13 @@ module.exports = (config, neutrino) => {
.add(`webpack-dev-server/client?${protocol}://${host}:${port}/`)
.add('webpack/hot/dev-server');
} else {
neutrino.use([
copy({ patterns: [{ context: SRC, from: `**/*` }], options: { ignore: ['*.js*'] } }),
progress(),
clean({ paths: [BUILD] }),
minify()
]);
neutrino.use(clean, { paths: [BUILD] });
neutrino.use(progress);
neutrino.use(minify);
neutrino.use(copy, {
patterns: [{ context: SRC, from: `**/*` }],
options: { ignore: ['*.js*'] }
});
config.output.filename('[name].[chunkhash].bundle.js');
}
};

2
packages/neutrino-preset-web/package.json

@ -16,7 +16,6 @@
"bugs": "https://github.com/mozilla-neutrino/neutrino-dev/issues",
"dependencies": {
"babel-preset-env": "^1.1.10",
"deepmerge": "^1.3.2",
"exports-loader": "^0.6.4",
"imports-loader": "^0.7.1",
"webpack": "^2.2.1",
@ -30,6 +29,7 @@
"neutrino-middleware-html-loader": "^5.0.0",
"neutrino-middleware-html-template": "^5.0.0",
"neutrino-middleware-hot": "^5.0.0",
"neutrino-middleware-loader-merge": "^5.0.0",
"neutrino-middleware-image-loader": "^5.0.0",
"neutrino-middleware-progress": "^5.0.0",
"neutrino-middleware-minify": "^5.0.0",

4
packages/neutrino-preset-web/yarn.lock

@ -862,10 +862,6 @@ deep-extend@~0.4.0:
version "0.4.1"
resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.4.1.tgz#efe4113d08085f4e6f9687759810f807469e2253"
deepmerge@^1.3.2:
version "1.3.2"
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-1.3.2.tgz#1663691629d4dbfe364fa12a2a4f0aa86aa3a050"
delayed-stream@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"

8
packages/neutrino/src/neutrino.js

@ -12,12 +12,8 @@ class Neutrino extends EventEmitter {
this.options = options;
}
use(presets = []) {
if (!Array.isArray(presets)) {
presets = [presets];
}
presets.map(preset => preset(this.config, this));
use(preset, options = {}) {
preset(this, options);
}
handleErrors(err, stats) {

Loading…
Cancel
Save