Browse Source

Node.js HMR, source watching, named modules for Node and Web

v5.0.0-beta
Eli Perelman 8 years ago
parent
commit
e3c7b60210
  1. 3
      packages/neutrino-middleware-named-modules/index.js
  2. 20
      packages/neutrino-middleware-named-modules/package.json
  3. 1761
      packages/neutrino-middleware-named-modules/yarn.lock
  4. 3
      packages/neutrino-middleware-start-server/index.js
  5. 20
      packages/neutrino-middleware-start-server/package.json
  6. 7
      packages/neutrino-middleware-start-server/yarn.lock
  7. 18
      packages/neutrino-preset-node/index.js
  8. 5
      packages/neutrino-preset-node/package.json
  9. 2
      packages/neutrino-preset-web/index.js
  10. 1
      packages/neutrino-preset-web/package.json
  11. 7
      packages/neutrino/src/neutrino.js

3
packages/neutrino-middleware-named-modules/index.js

@ -0,0 +1,3 @@
const { NamedModulesPlugin } = require('webpack');
module.exports = ({ config }) => config.plugin('named-modules').use(NamedModulesPlugin);

20
packages/neutrino-middleware-named-modules/package.json

@ -0,0 +1,20 @@
{
"name": "neutrino-middleware-named-modules",
"version": "5.0.0",
"description": "Neutrino middleware for adding named modules for better module names",
"main": "index.js",
"keywords": [
"neutrino",
"neutrino-middleware",
"named",
"modules"
],
"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": {
"webpack": "^2.2.1"
}
}

1761
packages/neutrino-middleware-named-modules/yarn.lock

File diff suppressed because it is too large

3
packages/neutrino-middleware-start-server/index.js

@ -0,0 +1,3 @@
const StartServerPlugin = require('start-server-webpack-plugin');
module.exports = ({ config }, options) => config.plugin('start-server').use(StartServerPlugin, options.name);

20
packages/neutrino-middleware-start-server/package.json

@ -0,0 +1,20 @@
{
"name": "neutrino-middleware-start-server",
"version": "5.0.0",
"description": "Neutrino middleware for starting a server after a build",
"main": "index.js",
"keywords": [
"neutrino",
"neutrino-middleware",
"start",
"server"
],
"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": {
"start-server-webpack-plugin": "^2.1.2"
}
}

7
packages/neutrino-middleware-start-server/yarn.lock

@ -0,0 +1,7 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
start-server-webpack-plugin@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/start-server-webpack-plugin/-/start-server-webpack-plugin-2.1.2.tgz#5489bd97ec61e85e41038d0063021744d6ed98c3"

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

@ -4,6 +4,9 @@ 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 startServer = require('neutrino-middleware-start-server');
const hot = require('neutrino-middleware-hot');
const namedModules = require('neutrino-middleware-named-modules');
const nodeExternals = require('webpack-node-externals');
const { join } = require('path');
@ -18,6 +21,7 @@ const PKG = require(join(CWD, 'package.json'));
module.exports = neutrino => {
const { config } = neutrino;
neutrino.use(namedModules);
neutrino.use(compile, {
include: [SRC, TEST],
babel: {
@ -40,7 +44,7 @@ module.exports = neutrino => {
.set('__dirname', false)
.end()
.devtool('source-map')
.externals([nodeExternals()])
.externals([nodeExternals({ whitelist: [/^webpack/] })])
.context(CWD)
.entry('index')
.add(join(SRC, 'index.js'))
@ -49,7 +53,7 @@ module.exports = neutrino => {
.path(BUILD)
.filename('[name].js')
.libraryTarget('commonjs2')
.chunkFilename('[id].[chunkhash].js')
.chunkFilename('[id].[hash:5]-[chunkhash:7].js')
.end()
.resolve
.modules
@ -80,6 +84,16 @@ module.exports = neutrino => {
patterns: [{ context: SRC, from: `**/*` }],
options: { ignore: ['*.js*'] }
});
} else {
config
.devtool('inline-sourcemap')
.entry('index')
.add('webpack/hot/poll?1000')
.end()
.output.options.set('devtoolModuleFilenameTemplate', '[absolute-resource-path]');
neutrino.use(hot);
neutrino.use(startServer, join(SRC, 'index.js'));
}
if (config.module.rules.has('lint')) {

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

@ -23,8 +23,11 @@
"neutrino-middleware-clean": "^5.0.0",
"neutrino-middleware-compile-loader": "^5.0.0",
"neutrino-middleware-copy": "^5.0.0",
"neutrino-middleware-hot": "^5.0.0",
"neutrino-middleware-loader-merge": "^5.0.0",
"neutrino-middleware-progress": "^5.0.0"
"neutrino-middleware-named-modules": "^5.0.0",
"neutrino-middleware-progress": "^5.0.0",
"neutrino-middleware-start-server": "^5.0.0"
},
"peerDependencies": {
"neutrino": "^5.0.0"

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

@ -12,6 +12,7 @@ const progress = require('neutrino-middleware-progress');
const clean = require('neutrino-middleware-clean');
const minify = require('neutrino-middleware-minify');
const loaderMerge = require('neutrino-middleware-loader-merge');
const namedModules = require('neutrino-middleware-named-modules');
const { join } = require('path');
const CWD = process.cwd();
@ -53,6 +54,7 @@ module.exports = neutrino => {
neutrino.use(fontLoader);
neutrino.use(imageLoader);
neutrino.use(htmlTemplate);
neutrino.use(namedModules);
neutrino.use(compileLoader, {
include: [SRC, TEST],
babel: {

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

@ -31,6 +31,7 @@
"neutrino-middleware-hot": "^5.0.0",
"neutrino-middleware-loader-merge": "^5.0.0",
"neutrino-middleware-image-loader": "^5.0.0",
"neutrino-middleware-named-modules": "^5.0.0",
"neutrino-middleware-progress": "^5.0.0",
"neutrino-middleware-minify": "^5.0.0",
"neutrino-middleware-style-loader": "^5.0.0"

7
packages/neutrino/src/neutrino.js

@ -66,11 +66,6 @@ class Neutrino extends EventEmitter {
return this.devServer();
}
if (config.target === 'node') {
console.log('Warning: This preset does not support watch compilation. Falling back to a one-time build.');
return this.builder();
}
return this.watcher();
})
.then(() => this.emitForAll('start', args));
@ -110,9 +105,11 @@ class Neutrino extends EventEmitter {
watcher() {
return new Promise(resolve => {
const building = ora('Waiting for initial build to finish').start();
const config = this.getWebpackOptions();
const compiler = webpack(config);
const watcher = compiler.watch(config.watchOptions || {}, (err, stats) => {
building.succeed('Build completed');
this.handleErrors(err, stats);
});

Loading…
Cancel
Save