neutrino.js内联源middelware

时间:2017-07-05 16:08:30

标签: javascript neutrino

目标是让neutrino build生成一个index.html,内联所有来源。我正在尝试使用html-inline-source webpackplugin我构建了一些中间件并将其添加到我的neutrinorc.js文件中

这是中间件文件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
    )
  ]);

这里是`neutrinorc.js文件

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

neutrino-inline.js文件与neutrinorc.js一起位于根目录中。

它不起作用。那是文件没有内联。但是没有错误。

更新:添加了中微子构建的输出--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'

}

0 个答案:

没有答案