var path = require('path') var utils = require('./utils') var config = require('../config') var vueLoaderConfig = require('./vue-loader.conf') const webpack = require('webpack') const manifest = require('../vendor-manifest.json') // Gzip const CompressionPlugin = require("compression-webpack-plugin"); function resolve(dir) { return path.join(__dirname, '..', dir) } module.exports = { entry: { // app: './src/main.js', app: ['babel-polyfill', './src/main.js'] }, // 防止有依赖关联到fs而报错,浏览器不让用 fs node: { fs: "empty" }, output: { path:process.env.NODE_ENV === 'production'? config.build.assetsRoot:config.test.assetsRoot, filename: '[name].js', publicPath: process.env.NODE_ENV === 'production' ? config.build.assetsPublicPath :process.env.NODE_ENV === 'test' ?config.test.assetsPublicPath :config.dev.assetsPublicPath }, resolve: { extensions: ['.js', '.vue', '.json'], alias: { 'vue$': 'vue/dist/vue.esm.js', '@': resolve('src'), 'scss_global': '@/styles/global.scss', 'api': '@/api', 'utils': '@/utils', 'components': '@/components', 'common': '@/common' } }, externals:{ "vue":"Vue", "jQuery": "jQuery" }, plugins: [ new webpack.DllReferencePlugin({ manifest }), new CompressionPlugin({ algorithm: "gzip", test: /\.js$|\.html$|\.css$/, // 匹配文件名 minRatio: 0.8, // 压缩率小于1才会压缩 threshold: 10240, // 对超过10k的数据压缩 deleteOriginalAssets: false, // 是否删除未压缩的源文件 }), // new webpack.ProvidePlugin({ // $: "jquery", // jQuery: "jquery", // 'window.jQuery': 'jquery', // jQuery: 'jquery' // }) ], module: { rules: [ { test: /\.vue$/, loader: 'vue-loader', options: vueLoaderConfig }, { test: /\.js$/, loader: 'babel-loader', include: [ resolve('src'), resolve('static'), resolve('/node_modules/element-ui'), ] }, { test: /\.(png|jpe?g|gif|svg)(\?.*)?$/, loader: 'url-loader', options: { limit: 10000, name: utils.assetsPath('img/[name].[hash:7].[ext]') } }, { test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, loader: 'url-loader', options: { limit: 10000, name: utils.assetsPath('fonts/[name].[hash:7].[ext]') } } ] } }