Javascript 如何将moment.js加载到网页包中

Javascript 如何将moment.js加载到网页包中,javascript,webpack,momentjs,Javascript,Webpack,Momentjs,我想将momente.js作为插件加载到webpack中。有人知道怎么做吗?在我的主干视图中尝试调用define('moment')时,我发现错误“moment”未定义 以下是我的网页包配置: app.use(webpackMiddleware(webpack({ context: __dirname + '/src', entr: './admin-entry.js', entry: { 'admin-entry': './admin-entry.js'

我想将momente.js作为插件加载到webpack中。有人知道怎么做吗?在我的主干视图中尝试调用
define('moment')
时,我发现错误“moment”未定义

以下是我的网页包配置:

app.use(webpackMiddleware(webpack({
    context: __dirname + '/src',
    entr: './admin-entry.js',
    entry: {
        'admin-entry': './admin-entry.js',
        'admin-login': './admin-login.js'
    },
    output: {
        path: '/webpack',
        publicPath: '/webpack',
        filename: '[name].js'
    },

    module: {
        noParse: [
            new RegExp(jqueryPath),
            new RegExp(lodashPath),
            new RegExp(qPath),
            new RegExp(cookiePath),
            new RegExp(momentPath),
            new RegExp(dateRangePickerPath)
        ]

    },
    resolve: {
        alias: {
            'jquery': jqueryPath,
            'lodash': lodashPath,
            'underscore': lodashPath,
            'backbone': backbonePath,
            'cookie': cookiePath,
            'daterangepicker': dateRangePickerPath,
            'moment': momentPath,
            'q': qPath
        },
        modulesDirectories: [
            'node_modules'
        ]
    },
    devtool: 'eval-source-map',
    plugins: [
        new webpack.SourceMapDevToolPlugin('webpack/[file].map', null, '[absolute-resource-path]', '[absolute-resource-path]')
    ]
}), {
    noInfo: false,
    quiet: false,
    lazy: false,
    // switch into lazy mode
    // that means no watching, but recompilation on every request
    watchOptions: {
        aggregateTimeout: 300,
        poll: true
    },
    publicPath: '/webpack',
    // public path to bind the middleware to
    // use the same as in webpack

    stats: {
        colors: true
    }
}));

首先,确保使用npm命令安装矩

npm安装力矩

现在您应该在node_modules文件夹中有了这个时刻。然后,您应该将moment作为全局变量添加到项目中,以便更改Webpack来为您解决它。要执行此操作,请更改Webpack.config.js文件,如下所示:

    plugins: [
      .... 
      new webpack.ProvidePlugin({
          moment : 'moment'
      })
      ....
    ]

您是否通过npm安装了moment?对我来说,
别名:{“矩”:“矩/min/moment with locales”很好