Плагины игнорируются шаблоном веб-пакета Vue - PullRequest
0 голосов
/ 04 июня 2018

Вот мой конфиг веб-пакета, в котором я пытаюсь добавить плагин IgnorePlugin, чтобы удалить локали с момента создания моего приложения.Однако, выполняя «npm run build» для компиляции производственной сборки, я не могу сразу удалить локали.Есть идеи, что может быть не так?

файл index.js

'use strict'
// Template version: 1.3.1
// see http://vuejs-templates.github.io/webpack for documentation.

const path = require('path')
var webpack = require("webpack");
module.exports = {
    dev: {

        // Paths
        assetsSubDirectory: 'static',
        assetsPublicPath: '/',
        proxyTable: {},

        // Various Dev Server settings
        host: 'localhost', // can be overwritten by process.env.HOST
        port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
        autoOpenBrowser: false,
        errorOverlay: true,
        notifyOnErrors: true,
        poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-


        /**
         * Source Maps
         */

        // https://webpack.js.org/configuration/devtool/#development
        devtool: 'cheap-module-eval-source-map',

        // If you have problems debugging vue-files in devtools,
        // set this to false - it *may* help
        // https://vue-loader.vuejs.org/en/options.html#cachebusting
        cacheBusting: true,

        cssSourceMap: true
    },

    build: {
        // Template for index.html
        index: path.resolve(__dirname, '../dist/index.html'),

        // Paths
        assetsRoot: path.resolve(__dirname, '../dist'),
        assetsSubDirectory: 'static',
        assetsPublicPath: '/',

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

        /**
         * Source Maps
         */

        productionSourceMap: true,
        // https://webpack.js.org/configuration/devtool/#production
        devtool: '#source-map',

        // Gzip off by default as many popular static hosts such as
        // Surge or Netlify already gzip all static assets for you.
        // Before setting to `true`, make sure to:
        // npm install --save-dev compression-webpack-plugin
        productionGzip: false,
        productionGzipExtensions: ['js', 'css'],

        // Run the build command with an extra argument to
        // View the bundle analyzer report after build finishes:
        // `npm run build --report`
        // Set to `true` or `false` to always turn it on or off
        bundleAnalyzerReport: process.env.npm_config_report
    }
}

файл prod.env.js

'use strict'
module.exports = {
  NODE_ENV: '"production"'
}

dev.env.js

'use strict'
const merge = require('webpack-merge')
const prodEnv = require('./prod.env')

module.exports = merge(prodEnv, {
  NODE_ENV: '"development"'
})

1 Ответ

0 голосов
/ 04 июня 2018

Согласно этой теме на Github, указанной официальной документацией: https://github.com/moment/moment/issues/2373

Вы можете попробовать как ldrick answer:

Это соответствующие части в моем webpack.config.js.

const path = require("path");
const webpack = require("webpack");

module.exports = () => {
    return {
        // ...
        resolve: {
            // Use src Moment.js to be optimized and packed.
            alias: {
                moment$: "moment/src/moment",
            },
        },
        // ...
        plugins: [
            // Switch context for Moment.js locales.
            new webpack.ContextReplacementPlugin(/^\.\/locale$/, context => {
                // Don't touch anything else then "moment".
                if (!/\/moment\//.test(context.context)) {
                    return;
                }
                // Working with "moment/src/moment" instead of "moment" requires
                // redirecting "./locale" back to "../../locale".
                Object.assign(context, {
                    // Want all locales, enable this line.
                    // regExp: /^\.\/\w+/,
                    // Just use some locales, enable this line.
                    // regExp: /de|fr|hu/,
                    // Don't use any locales except default "en".
                    regExp: undefined,
                    request: "../../locale",
                });
            }),
            // ...
        ],
        // ...
    };
};

Или вместо new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/) попробуйте это выражение (похоже, не стоит импортировать файлы локаций при сборке):

new webpack.ContextReplacementPlugin(
      /moment[\/\\]locale$/,
      /en|de|fr|es|pl|ua|ru/
    ),

(измените языки в зависимости от того, что вы используете).

Надеюсь, это поможет или хотя бы даст вам немного света!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...