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

module.exports = yo()
    .entry('./public/app.js')
    .output({
        path: `dist/statics/${config.appName}/`,
        publicPath: config.assetUrl
    })
    .style({
        preLoaders: {
            scss: true
        }
    })
    .resolve({
        alias: {
            vue: 'vue/dist/vue.common.js',
            '@dist': path.join(__dirname, '../dist'),
        },
        modules: [
            path.join(__dirname, '../node_modules'),
            path.join(__dirname, '../public'),
        ]
    })
    .js({
        babel: {
            exclude: [/node_modules/],
        }
    })
    .vue()
    .html(false)
    .merge({
        plugins: [
            new webpack.ProvidePlugin({
                $: 'yoho-jquery',
                jQuery: 'yoho-jquery',
                'window.jQuery': 'yoho-jquery'
            }),
        ],
        optimization: {
            splitChunks: {
                chunks() {
                    return false;
                },
                cacheGroups: {
                    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)/,
                    }
                }
            }
        },
        module: {
            rules: [{
                test: /\.hbs$/,
                use: {
                    loader: 'handlebars-loader',
                    options: {
                        helperDirs: [
                            path.join(__dirname, '../public/js/common/helpers')
                        ],
                        partialDirs: [
                            path.join(__dirname, '../doraemon/views/partial')
                        ]
                    }
                },
            }, {
                test: /yoho\.entry\.js/,
                loader: path.resolve(__dirname, './yoho-entry-loader'),
            }]
        }
    });