Laravel mix webpack - 导入Moment.js时忽略语言环境

时间:2017-07-27 15:00:41

标签: laravel webpack momentjs laravel-mix

我想仅从 Moment.js 加载2个区域设置en-gbfr-ch,然后将moment类分配给范围{{1}在我的Vuejs组件中到处使用库。

目前,我的window有以下要求行:

app.js

我怀疑这可以通过solutions here(将 IgnorePlugin ContextReplacementPlugin 添加到window.moment = require('moment') )来实现:

webpack.config.js

OR

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; 时,您应该在哪里添加这些代码(webpack.config.js和/或app.js和/或webpack.mix.js)以忽略所有其他区域设置?

2 个答案:

答案 0 :(得分:1)

  mix.webpackConfig({
    plugins: [
      new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
    ]
  })

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

答案 1 :(得分:0)

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 },
  },
});