【问题标题】:Laravel mix webpack - Ignore locales when importing Moment.jsLaravel mix webpack - 导入 Moment.js 时忽略语言环境
【发布时间】:2017-07-27 15:00:41
【问题描述】:

我想仅从 Moment.js 加载 2 个语言环境 en-gbfr-ch,然后将 moment 类分配给 scopewindow 以在我的任何地方使用该库Vuejs 组件。

目前,我的app.js 有这个要求行:

window.moment = require('moment')

我怀疑它可以通过 solutions here 来完成(将 IgnorePluginContextReplacementPlugin 添加到 webpack.config.js):

plugins.push(new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en-gb|fr-ch/))
module.exports.plugins = plugins;

plugins.push(new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/))
module.exports.plugins = plugins;

在导入 momentjs 时,您应该在哪里添加这些代码(webpack.config.js 和/或 app.js 和/或 webpack.mix.js)以忽略所有其他语言环境?

【问题讨论】:

    标签: laravel webpack momentjs laravel-mix


    【解决方案1】:
      mix.webpackConfig({
        plugins: [
          new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
        ]
      })
    

    来源:https://laracasts.com/discuss/channels/elixir/laravel-mix-prevent-momentjs-locales

    【讨论】:

      【解决方案2】:
      mix.webpackConfig( webpack => {
        plugins: [
          new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
        ]
      });
      

      这样您就不必在文件顶部导入 webpack,这有时会导致错误。

      你也可以像这样放置其他必要的选项

      mix.webpackConfig( webpack => {
        plugins: [
          new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
        ],
        resolve: {
          extensions: ['.js', '.vue'],
          alias: {
            '@': __dirname + '/resources',
            '@root': __dirname,
            '@pages': __dirname + '/resources/js/pages'
          },
          fallback: { "path": false },
        },
      });
      

      【讨论】:

        猜你喜欢
        • 2020-03-29
        • 1970-01-01
        • 2022-01-07
        • 2014-10-12
        • 2019-10-25
        • 1970-01-01
        • 1970-01-01
        • 2020-09-29
        • 2014-12-26
        相关资源
        最近更新 更多