yo.base.conf.js 2.13 KB
const yo = require('yo-cli');
const webpack = require('webpack');
const path = require('path');
const config = require('../config/common');
const swPlugin = require('./sw.config');

module.exports = yo()
    .entry('./public/app.js')
    .output({
        path: `dist/statics/${config.appName}/`,
        publicPath: config.assetUrl,
        crossOriginLoading: 'anonymous'
    })
    .style({
        extract: true
    })
    .js({
        chunk: {
            runtime: false,
            cacheGroups: {
                default: false,
                commons: {
                    chunks: 'all',
                    name: 'vendors',
                    test: /node_modules\/(yoho-jquery[$\/]|core-js|yoho-cookie|yoho-qs|babel-runtime|yoho-jquery-lazyload)/, //eslint-disable-line
                },
                vue: {
                    priority: 1,
                    chunks: 'all',
                    name: 'vue',
                    test: /node_modules\/vue/,
                },
                eachart: {
                    priority: 1,
                    chunks: 'all',
                    name: 'eachart',
                    test: /node_modules\/(echart|zrender)/,
                },
                swiper: {
                    priority: 1,
                    chunks: 'all',
                    name: 'swiper',
                    test: /node_modules\/(yoho-swiper)/,
                }
            }
        }
    })
    .resolve({
        modules: [
            path.join(__dirname, '../public'),
        ]
    })
    .vue()
    .hbs({
        helperDirs: [
            path.join(__dirname, '../public/js/common/helpers')
        ],
        partialDirs: [
            path.join(__dirname, '../doraemon/views/partial')
        ]
    })
    .merge({
        plugins: [
            swPlugin,
            new webpack.ProvidePlugin({
                $: 'yoho-jquery',
                jQuery: 'yoho-jquery',
                'window.jQuery': 'yoho-jquery'
            }),
        ],
        module: {
            rules: [{
                test: /yoho\.pages\.js/,
                loader: path.resolve(__dirname, './yoho-pages-loader'),
            }]
        }
    });