DLLPlugin 和 DLLReferencePlugin

使用 webpack 下的 DLLPlugin 和 DLLReferencePlugin 优化项目。

公共模块按需打包

在项目进行中,会应用很多公共的模块,其实这些模块是不会变动的,在后期项目优化的时候,用到了 webpack 下的 DLLPluginDLLReferencePlugin ,记录一下。

配置 dll.config.js

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

// 需要提取的公共模块
const vendors = [
    'vue',
    'vue-router',
    'lodash',
    'vuex',
    'fastclick',
    'axios'
];

module.exports = {
    output: {
        path: path.resolve(__dirname, '../static/js'), // 打爆出来的文件存放路径
        filename: '[name].dll.js', // 文件名
        library: '[name]_library' // 
    },
    entry: {
        vendor: vendors, // 公共的模块
    },
    plugins: [
        new webpack.DllPlugin({
            // 输出路径
            path: path.join(__dirname, '.', '[name]-manifest.json'),
            // 与上面的 output.library 对应
            name: '[name]_library',
            // 上下文环境
            context: __dirname
        }),
        // 压缩
        new webpack.optimize.UglifyJsPlugin({
            compress: {
                warnings: false
            },
            sourceMap: false
        }),
    ],
};

执行公共模块压缩

webpack --config dll.config.js

执行后会生成一个 js 文件和一个 json 文件,json 文件用于 webpack 打包, js 文件直接在 index 上引用即可。

配置 webpack

module.exports = {
    entry: {
        ···
    },
    output: {
        ···
    },
    resolve: {
        ···
    },
    module: {
        ···
    },
    plugins: [
        new webpack.DllReferencePlugin({
            // 与 dll.config.js 中的 context 一致
            context: __dirname,
            // 生成的 json 文件的地址
            manifest: require('./vendor-manifest.json')
        })
    ]
}

在配置项中加入 DllReferencePlugin 即可。

Read more

Gitlab 搭建

Gitlab 搭建

为什么? 想要自己搭建一个代码仓库无非是以下几点原因: 1. 公司内部项目 2. 自己的项目,但不适合在公网 3. 大部分的 git 仓库虽然有私有服务,但价格都不便宜,甚至不如一台云服务器来的便宜 配置及安装文档 Gitlab * 由于 gitlab 会用到 22 端口端口转发的化就走不了 git clone 的默认配置,且占用内存较高,不推荐使用 docker 进行部署; * 由于 gitlab 自带 nginx 默认情况下会与属主机的 nginx 冲突,因此推荐只使用 gitlab 自带的 nginx 进行端口转发; 最小化配置 # path /etc/gitlab/gitlab.rb external_url 'http://git.

By breeze
NPM 私服

NPM 私服

verdaccio 私服搭建,搭建过程中的一些问题以及解决: * docker compose 启动后,可能会报错:配置找不到,添加 config.yaml 文件到映射的 ./conf 目录即可,config.yaml 具体内容可在官网找到,下方也有最小化配置。 services: verdaccio: image: verdaccio/verdaccio container_name: 'verdaccio' networks: - node-network environment: - VERDACCIO_PORT=4873 - VERDACCIO_PUBLIC_URL=http://npm.demo.com ports: - '10001:4873'

By breeze