123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- var path = require('path')
- var config = require('../config')
- var utils = require('./utils')
- var webpack = require('webpack')
- var merge = require('webpack-merge')
- var baseWebpackConfig = require('./webpack.base.conf')
- var ExtractTextPlugin = require('extract-text-webpack-plugin')
- var HtmlWebpackPlugin = require('html-webpack-plugin')
- var CleanPlugin = require('clean-webpack-plugin')
- var glob = require('glob');
- var env = config.build.env
-
- var webpackConfig = merge(baseWebpackConfig, {
- module: {
- loaders: utils.styleLoaders({ sourceMap: config.build.productionSourceMap, extract: true })
- },
- devtool: config.build.productionSourceMap ? '#source-map' : false,
- output: {
- path: config.build.assetsRoot,
- filename: utils.assetsPath('js/[name].[chunkhash].js'),
- chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
- },
- vue: {
- loaders: utils.cssLoaders({
- sourceMap: config.build.productionSourceMap,
- extract: true
- })
- },
- plugins: [
-
- new webpack.DefinePlugin({
- 'process.env': env
- }),
- new webpack.optimize.UglifyJsPlugin({
- compress: {
- warnings: false
- }
- }),
- new CleanPlugin(['../dist']),
- new webpack.optimize.OccurenceOrderPlugin(),
-
- new ExtractTextPlugin(utils.assetsPath('css/[name].[contenthash].css')),
-
-
-
-
- new webpack.optimize.CommonsChunkPlugin({
- name: 'vendor',
- minChunks: function (module, count) {
-
- return (
- module.resource &&
- /\.js$/.test(module.resource) &&
- module.resource.indexOf(
- path.join(__dirname, '../node_modules')
- ) === 0
- )
- }
- }),
-
-
- new webpack.optimize.CommonsChunkPlugin({
- name: 'manifest',
- chunks: ['vendor']
- })
- ]
- })
-
- if (config.build.productionGzip) {
- var CompressionWebpackPlugin = require('compression-webpack-plugin')
-
- webpackConfig.plugins.push(
- new CompressionWebpackPlugin({
- asset: '[path].gz[query]',
- algorithm: 'gzip',
- test: new RegExp(
- '\\.(' +
- config.build.productionGzipExtensions.join('|') +
- ')$'
- ),
- threshold: 10240,
- minRatio: 0.8
- })
- )
- }
-
- module.exports = webpackConfig
-
- function getEntry(globPath) {
- var entries = {},
- basename, tmp, pathname;
- if (typeof (globPath) != "object") {
- globPath = [globPath]
- }
- globPath.forEach((itemPath) => {
- glob.sync(itemPath).forEach(function (entry) {
- basename = path.basename(entry, path.extname(entry));
- if (entry.split('/').length > 4) {
- tmp = entry.split('/').splice(-3);
- pathname = tmp.splice(0, 1) + '/' + basename;
- entries[pathname] = entry;
- } else {
- entries[basename] = entry;
- }
- });
- });
- return entries;
- }
-
- var pages = getEntry(['./src/module/*.html','./src/module/**/*.html']);
-
- for (var pathname in pages) {
-
- var conf = {
- filename: pathname + '.html',
- template: pages[pathname],
- inject: true,
-
- chunksSortMode: 'dependency'
- };
-
- if (pathname in module.exports.entry) {
- conf.chunks = ['manifest', 'vendor', pathname];
- conf.hash = true;
- }
-
- module.exports.plugins.push(new HtmlWebpackPlugin(conf));
- }
|