相关疑难解决方法(0)

webpack动态模块加载器由require

好吧,我已经搜索过高低,但如果webpack不可能,则无法可靠地确定.

https://github.com/webpack/webpack/tree/master/examples/require.context 似乎表明可以将字符串传递给函数并加载模块...

但我的尝试不起作用:webpack.config.js

'use strict';
let webpack     = require('webpack'),
    jsonLoader  = require("json-loader"),
    path        = require("path"),
    fs          = require('fs'),
    nodeModules = {};

fs.readdirSync('node_modules')
    .filter(function(x) {
        return ['.bin'].indexOf(x) === -1;
    })
    .forEach(function(mod) {
        nodeModules[mod] = 'commonjs ' + mod;
    });


let PATHS = {
    app: __dirname + '/src'
};

module.exports = {
    context: PATHS.app,
    entry: {
        app: PATHS.app+'/server.js'
    },
    target: 'node',
    output: {
        path: PATHS.app,
        filename: '../build/server.js'
    },
    externals: nodeModules,
    performance: {
        hints: "warning"
    },
    plugins: [
        jsonLoader
    ],
    resolve: { …
Run Code Online (Sandbox Code Playgroud)

javascript require node.js webpack webpack-2

10
推荐指数
3
解决办法
1万
查看次数

标签 统计

javascript ×1

node.js ×1

require ×1

webpack ×1

webpack-2 ×1