Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webpack-添加数组原生方法 #21

Open
PleaseStartYourPerformance opened this issue May 21, 2021 · 0 comments
Open

Webpack-添加数组原生方法 #21

PleaseStartYourPerformance opened this issue May 21, 2021 · 0 comments

Comments

@PleaseStartYourPerformance
Copy link
Owner

入口文件中

const {getPlugins} = require('./utils/getPlugins');
const {getEntries} = require('./utils/getEntries');
const {getLoaders} = require('./utils/getLoaders');
const {getAlias} = require('./utils/getAlias');
const path = require('path');

module.exports = {
    entry: getEntries(),//注意这里------------------------------
    output: {
        path: path.join(__dirname, '../dist'),
    },
    resolve: {
        extensions: ['.js', '.ts', '.tsx', '.less', '.css'],
        alias: getAlias()
    },
    stats: 'errors-only',
    module: {
        rules: getLoaders()
    },
    optimization: {
        splitChunks: {
            chunks: 'all',
            name: 'chunk'
        }
    },
    plugins: getPlugins()
};

getEntries

const resolve = require('./index').resolve;

function getEntries() {
    return {
        bundle: [
            resolve('./src/old-pages/js/tags-dep.js'),
            resolve('./src/old-pages/js/router.js'),
            resolve('./src/old-pages/js/boot.js'),

            resolve('./thirdsrc/froala/js/froala_editor.js'),
            resolve('./thirdsrc/froala/js/plugins/align.min.js'),
            resolve('./thirdsrc/froala/js/plugins/colors.min.js'),
            resolve('./thirdsrc/froala/js/plugins/draggable.min.js'),
            resolve('./thirdsrc/froala/js/plugins/font_size.min.js'),
            resolve('./thirdsrc/froala/js/plugins/font_family.min.js'),
            resolve('./thirdsrc/froala/js/plugins/fullscreen.min.js'),
            resolve('./thirdsrc/froala/js/plugins/image.js'),
            resolve('./thirdsrc/froala/js/plugins/image_manager.min.js'),
            resolve('./thirdsrc/froala/js/plugins/line_breaker.min.js'),
            resolve('./thirdsrc/froala/js/plugins/link.js'),
            resolve('./thirdsrc/froala/js/plugins/lists.min.js'),
            resolve('./thirdsrc/froala/js/plugins/paragraph_format.min.js'),
            resolve('./thirdsrc/froala/js/plugins/table.min.js'),
            resolve('./thirdsrc/froala/js/plugins/url.min.js'),
            resolve('./thirdsrc/froala/js/plugins/word_paste.js'),
            resolve('./thirdsrc/froala/js/languages/zh_cn.js'),
        ]
    };
}
exports.getEntries = getEntries;

tags-dep.js (数组原生添加方法)

/* eslint-disable */

/*
 *  数组方法扩展
 */
if (![].indexOf) {
    Array.prototype.indexOf = function(val) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] == val) return i;
        }
        return -1;
    };
}
Array.prototype.remove = function(val) {
    var index = this.indexOf(val);
    if (index > -1) {
        this.splice(index, 1);
    }
};

Array.prototype.removeBy = function(key, val) {
    for (var i = 0; i < this.length; i++) {
        if (Object.prototype.toString.call(this[i]) === '[object Object]') {
            if (this[i][key] === val) {
                this.splice(i, 1);
            }
        }
    }
};

Array.prototype.unique = function() {
    var res = [];
    var json = {};
    for (var i = 0; i < this.length; i++) {
        if (!json[this[i]]) {
            res.push(this[i]);
            json[this[i]] = 1;
        }
    }
    return res;
};

Array.prototype.clone = function() {
    return [].concat(this);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant