0

The goal is to have neutrino build produce a single index.html, with all sources inlined. I am trying to use the html-inline-source webpackplugin I have constructed some middleware and added it my neutrinorc.js file

Here is the middleware file neutrino-inline.js

const HtmlInlineSourceWebpackPlugin = require("html-inline-source-webpack-plugin");
const merge = require("deepmerge");
const path = require("path");

module.exports = ({
    config
  }, options = {}) =>
  config.plugin("inline").use(HtmlInlineSourceWebpackPlugin, [
    merge({
        compress: false,
        attribute: false,
        rootpath: path.resolve("./src")
      },
      options
    )
  ]);

and here is the `neutrinorc.js file

module.exports = {
  use: [
    "neutrino-preset-react",
    "neutrino-middleware-env",
    "./neutrino-inline.js"
  ]
};

The neutrino-inline.js file is in the root along with neutrinorc.js.

It isn't working. That is the files are not inlined. But there are no errors.

UPDATE: added the output of neutrino build --inspect

{
context: '/Users/toddgeist/Desktop/kart-lite-api',
devtool: 'source-map',
entry: {
    index: [
        '/Users/toddgeist/Desktop/kart-lite-api/src/index'
    ]
},
externals: [
    function(context, request, callback) {
        var moduleName = getModuleName(request, includeAbsolutePaths);
        if (contains(nodeModules, moduleName) && !containsPattern(whitelist, request)) {
            // mark this module as external
            // https://webpack.github.io/docs/configuration.html#externals
            return callback(null, importType + " " + request);
        };
        callback();
    }
],
module: {
    rules: [{
        exclude: [
            '/Users/toddgeist/Desktop/kart-lite-api/src/static'
        ],
        include: [
            '/Users/toddgeist/Desktop/kart-lite-api/src',
            '/Users/toddgeist/Desktop/kart-lite-api/test'
        ],
        test: /\.jsx?$/,
        use: [{
            loader: '/Users/toddgeist/Desktop/kart-lite-api/node_modules/babel-loader/lib/index.js',
            options: {
                cacheDirectory: true,
                plugins: [
                    [
                        '/Users/toddgeist/Desktop/kart-lite-api/node_modules/fast-async/plugin.js', {
                            spec: true
                        }
                    ],
                    '/Users/toddgeist/Desktop/kart-lite-api/node_modules/babel-plugin-dynamic-import-node/lib/index.js'
                ],
                presets: [
                    [
                        '/Users/toddgeist/Desktop/kart-lite-api/node_modules/babel-preset-env/lib/index.js', {
                            debug: false,
                            exclude: [
                                'transform-regenerator',
                                'transform-async-to-generator'
                            ],
                            modules: false,
                            targets: {
                                node: '8.0'
                            },

                            useBuiltIns: true
                        }
                    ]
                ]
            }
        }]
    }]
},
node: {
    __dirname: false,
    __filename: false
},
output: {
    chunkFilename: '[id].[hash:5]-[chunkhash:7].js',
    filename: '[name].js',
    libraryTarget: 'commonjs2',
    path: '/Users/toddgeist/Desktop/kart-lite-api/build'
},
plugins: [{
    options: {
        banner: 'require(\'source-map-support\').install();',
        raw: true,
        entryOnly: true
    },
    banner: 'require(\'source-map-support\').install();'
}, {
    paths: [
        '/Users/toddgeist/Desktop/kart-lite-api/build'
    ],
    options: {
        root: '/Users/toddgeist/Desktop/kart-lite-api',
        verbose: false,
        allowExternal: false,
        dry: false
    }
}, {
    apply: function apply(compiler) {
        var fileDependencies = [];
        var contextDependencies = [];
        var written = {};

        compiler.plugin('emit', function(compilation, cb) {
            debug('starting emit');
            var callback = function callback() {
                debug('finishing emit');
                cb();
            };

            var globalRef = {
                info: info,
                debug: debug,
                warning: warning,
                compilation: compilation,
                written: written,
                fileDependencies: fileDependencies,
                contextDependencies: contextDependencies,
                context: compiler.options.context,
                output: compiler.options.output.path,
                ignore: options.ignore || [],
                copyUnmodified: options.copyUnmodified,
                concurrency: options.concurrency
            };

            if (globalRef.output === '/' && compiler.options.devServer && compiler.options.devServer.outputPath) {
                globalRef.output = compiler.options.devServer.outputPath;
            }

            _bluebird2.default.each(patterns, function(pattern) {
                // Identify absolute source of each pattern and destination type
                return (0, _preProcessPattern2.default)(globalRef, pattern).then(function(pattern) {
                    // Every source (from) is assumed to exist here 
                    return (0, _processPattern2.default)(globalRef, pattern);
                });
            }).catch(function(err) {
                compilation.errors.push(err);
            }).finally(callback);
        });

        compiler.plugin('after-emit', function(compilation, cb) {
            debug('starting after-emit');
            var callback = function callback() {
                debug('finishing after-emit');
                cb();
            };

            // Add file dependencies if they're not already tracked
            _lodash2.default.forEach(fileDependencies, function(file) {
                if (_lodash2.default.includes(compilation.fileDependencies, file)) {
                    debug('not adding ' + file + ' to change tracking, because it\'s already tracked');
                } else {
                    debug('adding ' + file + ' to change tracking');
                    compilation.fileDependencies.push(file);
                }
            });

            // Add context dependencies if they're not already tracked
            _lodash2.default.forEach(contextDependencies, function(context) {
                if (_lodash2.default.includes(compilation.contextDependencies, context)) {
                    debug('not adding ' + context + ' to change tracking, because it\'s already tracked');
                } else {
                    debug('adding ' + context + ' to change tracking');
                    compilation.contextDependencies.push(context);
                }
            });

            callback();
        });
    }
}],
resolve: {
    extensions: [
        '.js',
        '.json'
    ],
    modules: [
        'node_modules',
        '/Users/toddgeist/Desktop/kart-lite-api/node_modules',
        '/Users/toddgeist/Desktop/kart-lite-api/node_modules/neutrino-preset-node/node_modules'
    ]
},

resolveLoader: {
    modules: [
        '/Users/toddgeist/Desktop/kart-lite-api/node_modules',
        '/Users/toddgeist/Desktop/kart-lite-api/node_modules/neutrino-preset-node/node_modules'
    ]
},
target: 'node'

}

toddgeist
  • 902
  • 9
  • 21
  • Could you also share the output of `neutrino build --inspect`? – Eli Jul 07 '17 at 20:54
  • yup. Updated with the output – toddgeist Jul 08 '17 at 23:25
  • I notice that you are using a `node` target, even though the React/Web preset sets it to `web`. Did you override this setting, and if so, for what purpose? Using the wrong target most likely will cause the HTML file to not be generated, hence why the plugin may not be working. – Eli Jul 10 '17 at 13:04
  • I did not knowingly set the target to `node`. Maybe it is `neutrino-middleware-env` that did that. I'll check – toddgeist Jul 11 '17 at 13:54

0 Answers0