const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const InlineManifestWebpackPlugin = require('inline-manifest-webpack-plugin')
const webpack = require('webpack')

module.exports = {
    entry: {
        //polyfill: 'babel-polyfill',
        main: 'docs/main.js',
        libs: [
            'vue',
            'vue-router',
            'prismjs',
            'vue-material'
        ],
        resource: [
            'prismjs/themes/prism-tomorrow.css',
            'docs/fonts/iconfont.css'
        ],
        vendor: [
            'docs/components/App.vue',
            'docs/components/CateView.vue',
            'docs/components/DocPreview.vue',
            'docs/components/Navigator.vue',
            'docs/components/RootFrame.vue'
        ]
    },
    output: {
        path: path.resolve(__dirname, '../dist'),
        filename: '[name].[hash:8].bundle.js',
        chunkFilename: '[name].[chunkhash:8].js'
    },
    devServer: {
        //实时刷新,
        hot: true,
        host: '127.0.0.1',
        port: 8088

    },
    module: {
        rules: [{
                test: /\.vue$/,
                use: ['vue-loader'],
                exclude: [/_cache/]
            },
            // {
            //     test: /\.js$/,
            //     use: ['babel-loader'],
            //     exclude: [/node_modules/]
            // },
            {
                test: /\.js$/,
                exclude: [/node_modules/, /md/],
                use: [{
                  loader: 'babel-loader',
                  options: {
                     presets: ['es2015']
                  }
                }]
              },
            {
                test: /\.md$/,
                use: ['vue-markdown-loader'],
                exclude: [/node_modules/]
            },
            {
                test: /\.css$/,
                use: ['style-loader', 'css-loader']
            },
            {
                test: /\.styl$/,
                use: ['style-loader', 'css-loader', 'stylus-loader']
            },
            {
                test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
                use: ['url-loader']
            },
            {
                test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
                use: ['url-loader']
            }
        ]
    },
    resolve: {
        alias: {
            docs: path.resolve(__dirname, '../docs')
        }
    },
    plugins: [
        new webpack.HashedModuleIdsPlugin(),
        new HtmlWebpackPlugin({
            template: path.resolve(__dirname, '../docs/template/index.html'),
            chunks: ['libs', 'vendor', 'resource', 'main']
        }),
        new webpack.optimize.CommonsChunkPlugin({
            names: ['vendor', 'libs', 'resource', 'manifest'],
            minChunks: Infinity
        }),
        new InlineManifestWebpackPlugin({
            name: 'webpackManifest'
        }),
        new webpack.ProvidePlugin({
            $: 'jquery',
            jQuery: 'jquery'
        })
    ]
}