const webpack = require('webpack'); const path = require('path'); const ExtractTextPlugin = require("extract-text-webpack-plugin"); const HtmlWebpackPlugin = require('html-webpack-plugin'); const WebpackDevServer = require('webpack-dev-server'); const entries = require('./webpack/entry.config.js'); const version = require('./package.json').version; const argv = require('yargs').argv; const ImageminPlugin = require('imagemin-webpack-plugin').default; const CopyWebpackPlugin = require('copy-webpack-plugin'); const dirVars = require('./webpack/dir.config.js'); const HtmlWebpackIncludeAssetsPlugin = require('html-webpack-include-assets-plugin'); let theme = { '@primary-color': '#58a3ff', '@link-color': '#58a3ff' }; let isWatch = argv.env.watch == 'watch'; let isDev = isWatch || argv.env.deploy == 'dev'; module.exports = (function () { let plugins = [ new webpack.optimize.CommonsChunkPlugin({ name: 'vendors', minChunks: 20 }), // new webpack.optimize.CommonsChunkPlugin({ // name: 'vendor', // minChunks: function (module) { // return ( // module.resource && // /\.js$/.test(module.resource) && // module.resource.indexOf( // path.join(__dirname, '../node_modules') // ) === 0 // ) // } // }), // new webpack.optimize.CommonsChunkPlugin({ // name: 'vendors', // chunks: ['vendor'] // }), /* 配置好Dll */ new webpack.DllReferencePlugin({ context: dirVars.staticRootDir, // 指定一个路径作为上下文环境,需要与DllPlugin的context参数保持一致,建议统一设置为项目根目录 manifest: require('./dll/'+argv.env.deploy+'/manifest.json') // 指定manifest.json }), // 把dll文件复制到打包后的文件中 new CopyWebpackPlugin([ { from: path.resolve('./dll/'+argv.env.deploy), to: (__dirname, './dll/'), ignore: ['.*'] } ]), // 将 dll.js 插入HTML里 new HtmlWebpackIncludeAssetsPlugin({ assets: [(__dirname, 'dll/dll.js'),(__dirname, 'dll/dll.css')], append: false }), new ExtractTextPlugin({ filename: "[name].css", disable: false, allChunks: true }), new webpack.ProvidePlugin({ $: "jquery", jQuery: "jquery" }), new HtmlWebpackPlugin({ title: '首页', filename: 'html/index.html', template: './template/index.html', chunks: ['vendors','index' ], chunksSortMode:"dependency" }), new HtmlWebpackPlugin({ title: '搜索页', filename: 'html/search.html', template: './template/search.html', chunks: ['vendors','search'], }), new HtmlWebpackPlugin({ title: '服务商主页', filename: 'html/facilitator.html', template: './template/newMenu/facilitator/facilitator.html', chunks: ['vendors','facilitator'], }), // new HtmlWebpackPlugin({ // title: '支付跳转页面', // filename: 'html/toPayment.html', // template: './template/toPayment.html', // chunks: ['toPayment', 'vendors'] // }), new HtmlWebpackPlugin({ title: '关于公司', filename: 'html/aboutUs.html', template: './template/aboutUs.html', chunks: ['aboutUs', 'vendors'] }), // new HtmlWebpackPlugin({ // title: '关于公司APP', // filename: 'html/APPaboutUs.html', // template: './template/APPaboutUs.html', // chunks: ['APPaboutUs', 'vendors'] // }), new HtmlWebpackPlugin({ title: '联系我们', filename: 'html/contactUs.html', template: './template/contactUs.html', chunks: ['contactUs', 'vendors'] }), // new HtmlWebpackPlugin({ // title: '科技服务', // filename: 'html/service.html', // template: './template/service.html', // chunks: ['service', 'vendors'] // }), new HtmlWebpackPlugin({ title: '注册', filename: 'html/register.html', template: './template/register.html', chunks: ['register', 'vendors'] }), // new HtmlWebpackPlugin({ // title: '会员', // filename: 'html/member.html', // template: './template/member.html', // chunks: ['member', 'vendors'] // }), // new HtmlWebpackPlugin({ // title: '科技交易', // filename: 'html/technologyTrading.html', // template: './template/technologyTrading.html', // chunks: ['technologyTrading', 'vendors'] // }), new HtmlWebpackPlugin({ title: '科技智库', filename: 'html/thinkTank.html', template: './template/thinkTank.html', chunks: ['thinkTank', 'vendors'] }), // new HtmlWebpackPlugin({ // title: '科技金融', // filename: 'html/financialIndex.html', // template: './template/financialIndex.html', // chunks: ['financialIndex', 'vendors'] // }), // new HtmlWebpackPlugin({ // title: '科技交易-技术专利', // filename: 'html/technologyTrading/achievement.html', // template: './template/technologyTrading/achievement.html', // chunks: ['technologyTrading/achievement', 'vendors'] // }), // new HtmlWebpackPlugin({ // title: '科技交易-技术需求', // filename: 'html/technologyTrading/demand.html', // template: './template/technologyTrading/demand.html', // chunks: ['technologyTrading/demand', 'vendors'] // }), new HtmlWebpackPlugin({ title: '科技交易-技术专利详情', filename: 'html/technologyTrading/achievementDetail.html', template: './template/technologyTrading/achievementDetail.html', chunks: ['technologyTrading/achievementDetail', 'vendors'] }), new HtmlWebpackPlugin({ title: '科技交易-技术需求详情', filename: 'html/technologyTrading/demandDetail.html', template: './template/technologyTrading/demandDetail.html', chunks: ['technologyTrading/demandDetail', 'vendors'] }), // new HtmlWebpackPlugin({ // title: '在线评估', // filename: 'html/technologyTrading/assessMent.html', // template: './template/technologyTrading/assessMent.html', // chunks: ['technologyTrading/assessMent', 'vendors'] // }), // new HtmlWebpackPlugin({ // title: '科技交易-技术成果下单页面', // filename: 'html/technologyTrading/achievementOrder.html', // template: './template/technologyTrading/achievementOrder.html', // chunks: ['technologyTrading/achievementOrder', 'vendors'] // }), // new HtmlWebpackPlugin({ // title: '科技交易-技术需求下单页面', // filename: 'html/technologyTrading/demandOrder.html', // template: './template/technologyTrading/demandOrder.html', // chunks: ['technologyTrading/demandOrder', 'vendors'] // }), new HtmlWebpackPlugin({ title: '智库咨询-智政详情', filename: 'html/thinkTank/policyDetail.html', template: './template/thinkTank/policyDetail.html', chunks: ['thinkTank/policyDetail', 'vendors'] }), new HtmlWebpackPlugin({ title: '智库咨询-智政列表', filename: 'html/thinkTank/policyList.html', template: './template/thinkTank/policyList.html', chunks: ['thinkTank/policyList', 'vendors'] }), new HtmlWebpackPlugin({ title: '智库咨询-智者详情', filename: 'html/thinkTank/thinkerDetail.html', template: './template/thinkTank/thinkerDetail.html', chunks: ['thinkTank/thinkerDetail', 'vendors'] }), // new HtmlWebpackPlugin({ // title: '科技金融-投资机构', // filename: 'html/financial/investmentInstitution.html', // template: './template/financial/investmentInstitution.html', // chunks: ['financial/investmentInstitution', 'vendors'] // }), // new HtmlWebpackPlugin({ // title: '科技金融-投资机构', // filename: 'html/financial/investmentDetail.html', // template: './template/financial/investmentDetail.html', // chunks: ['financial/investmentDetail', 'vendors'] // }), // new HtmlWebpackPlugin({ // title: '科技服务-高新认定', // filename: 'html/service/highTechCognizance.html', // template: './template/service/highTechCognizance.html', // chunks: ['service/highTechCognizance', 'vendors'] // }), // new HtmlWebpackPlugin({ // title: '科技服务-知识产权', // filename: 'html/service/propertyRight.html', // template: './template/service/propertyRight.html', // chunks: ['service/propertyRight', 'vendors'] // }), // new HtmlWebpackPlugin({ // title: '科技服务-高新认定', // filename: 'html/service/projectDetails.html', // template: './template/service/projectDetails.html', // chunks: ['service/projectDetails', 'vendors'] // }), // new HtmlWebpackPlugin({ // title: '科技服务-服务意向', // filename: 'html/service/purpose.html', // template: './template/service/purpose.html', // chunks: ['service/purpose', 'vendors'] // }), //newsApp new HtmlWebpackPlugin({ title: '新闻详情', filename: 'html/news/newsDetailApp.html', template: './template/news/newsDetailApp.html', chunks: ['news/newsDetailApp', 'vendors'] }), // new HtmlWebpackPlugin({ // title: '高企认定', // filename: 'html/news/appCognizance.html', // template: './template/news/appCognizance.html', // chunks: ['news/appCognizance', 'vendors'] // }), new HtmlWebpackPlugin({ title: '注册协议', filename: 'html/news/agreement.html', template: './template/news/agreement.html', chunks: ['news/agreement', 'vendors'] }), /* 2018-6 改版后科技需求 */ new HtmlWebpackPlugin({ title: '科技需求', filename: 'html/newMenu/demand.html', template: './template/newMenu/demand.html', chunks: ['newMenu/demand', 'vendors'] }), new HtmlWebpackPlugin({ title: '科技成果', filename: 'html/newMenu/achievement.html', template: './template/newMenu/achievement.html', chunks: ['newMenu/achievement', 'vendors'] }), new HtmlWebpackPlugin({ title: '科技成果列表', filename: 'html/newMenu/achievementList.html', template: './template/newMenu/achievementList.html', chunks: ['newMenu/achievementList', 'vendors'] }), new HtmlWebpackPlugin({ title: '科技需求列表', filename: 'html/newMenu/demandList.html', template: './template/newMenu/demandList.html', chunks: ['newMenu/demandList', 'vendors'] }), new HtmlWebpackPlugin({ title: '科技服务', filename: 'html/newMenu/services.html', template: './template/newMenu/services.html', chunks: ['newMenu/services', 'vendors'] }), new HtmlWebpackPlugin({ title: '科技服务列表', filename: 'html/newMenu/serviceList.html', template: './template/newMenu/serviceList.html', chunks: ['newMenu/serviceList', 'vendors'] }), new HtmlWebpackPlugin({ title: '科技服务详情', filename: 'html/newMenu/serviceDetails.html', template: './template/newMenu/serviceDetails.html', chunks: ['newMenu/serviceDetails', 'vendors'] }), new HtmlWebpackPlugin({ title: '购物车', filename: 'html/newMenu/shopList.html', template: './template/newMenu/shopList.html', chunks: ['newMenu/shopList', 'vendors'] }), new HtmlWebpackPlugin({ title: '专利列表', filename: 'html/newMenu/patentList.html', template: './template/newMenu/patentList.html', chunks: ['newMenu/patentList', 'vendors'] }), new HtmlWebpackPlugin({ title: '知识产权交易首页', filename: 'html/newMenu/tradingIndex.html', template: './template/newMenu/tradingIndex.html', chunks: ['newMenu/tradingIndex', 'vendors'] }), new HtmlWebpackPlugin({ title: '知识产权申请首页', filename: 'html/newMenu/patent.html', template: './template/newMenu/patent.html', chunks: ['newMenu/patent', 'vendors'] }), new HtmlWebpackPlugin({ title: '公司简介', filename: 'html/newMenu/companyProfile.html', template: './template/newMenu/companyProfile.html', chunks: ['newMenu/companyProfile', 'vendors'] }), new HtmlWebpackPlugin({ title: '高企认定', filename: 'html/newMenu/continueHigh.html', template: './template/newMenu/loading/continueHigh.html', chunks: ['newMenu/continueHigh', 'vendors'] }), new HtmlWebpackPlugin({ title: '实用新型专利', filename: 'html/newMenu/practicalPatent.html', template: './template/newMenu/loading/practicalPatent.html', chunks: ['newMenu/practicalPatent', 'vendors'] }), new HtmlWebpackPlugin({ title: '军工认证', filename: 'html/newMenu/militaryProject.html', template: './template/newMenu/loading/militaryProject.html', chunks: ['newMenu/militaryProject', 'vendors'] }), // new HtmlWebpackPlugin({ // title: '高企认定App', // filename: 'html/newMenu/continueHighApp.html', // template: './template/newMenu/landingPage/continueHighApp.html', // chunks: ['newMenu/continueHighApp', 'vendors'] // }), // new HtmlWebpackPlugin({ // title: '实用新型专利App', // filename: 'html/newMenu/practicalPatentApp.html', // template: './template/newMenu/landingPage/practicalPatentApp.html', // chunks: ['newMenu/practicalPatentApp', 'vendors'] // }), // new HtmlWebpackPlugin({ // title: '军工认证App', // filename: 'html/newMenu/militaryProjectApp.html', // template: './template/newMenu/landingPage/militaryProjectApp.html', // chunks: ['newMenu/militaryProjectApp', 'vendors'] // }), new HtmlWebpackPlugin({ title: '知识产权维权', filename: 'html/newMenu/safeguarding.html', template: './template/newMenu/safeguarding.html', chunks: ['newMenu/safeguarding', 'vendors'] }), new HtmlWebpackPlugin({ title: '知识产权维权列表', filename: 'html/newMenu/safeguardingList.html', template: './template/newMenu/safeguardingList.html', chunks: ['newMenu/safeguardingList', 'vendors'] }), new HtmlWebpackPlugin({ title: '知识产权维权详情', filename: 'html/newMenu/safeguardingDetail.html', template: './template/newMenu/safeguardingDetail.html', chunks: ['newMenu/safeguardingDetail', 'vendors'] }), //app // new HtmlWebpackPlugin({ // title: '评估', // filename: 'html/newMenu/app/assessment.html', // template: './template/newMenu/app/assessment.html', // chunks: ['newMenu/app/assessment', 'vendors'] // }), // new HtmlWebpackPlugin({ // title: '托管', // filename: 'html/newMenu/app/trusteeship.html', // template: './template/newMenu/app/trusteeship.html', // chunks: ['newMenu/app/trusteeship', 'vendors'] // }), // new HtmlWebpackPlugin({ // title: 'app维权', // filename: 'html/newMenu/app/safeguardApp.html', // template: './template/newMenu/app/safeguardApp.html', // chunks: ['newMenu/app/safeguardApp', 'vendors'] // }) new HtmlWebpackPlugin({ title: '高企自评', filename: 'html/evaluation/evaluate.html', template: './template/newMenu/evaluate.html', chunks: ['evaluation/evaluate','vendors'] }), new HtmlWebpackPlugin({ title: '知识产权顾问首页', filename: 'html/newMenu/adviser.html', template: './template/newMenu/adviser.html', chunks: ['newMenu/adviser', 'vendors'] }), new HtmlWebpackPlugin({ title: '知识产权顾问列表', filename: 'html/newMenu/adviserList.html', template: './template/newMenu/adviserList.html', chunks: ['newMenu/adviserList', 'vendors'] }), new HtmlWebpackPlugin({ title: '知识产权顾问详情', filename: 'html/newMenu/adviserDetail.html', template: './template/newMenu/adviserDetail.html', chunks: ['newMenu/adviserDetail', 'vendors'] }), new HtmlWebpackPlugin({ title: '品牌建设', filename: 'html/newMenu/brandBuild.html', template: './template/newMenu/loading/brandBuild.html', chunks: ['newMenu/brandBuild', 'vendors'] }), new HtmlWebpackPlugin({ title: '市场开括', filename: 'html/newMenu/marketOpen.html', template: './template/newMenu/loading/marketOpen.html', chunks: ['newMenu/marketOpen', 'vendors'] }), new HtmlWebpackPlugin({ title: '财税金融', filename: 'html/newMenu/taxFinance.html', template: './template/newMenu/loading/taxFinance.html', chunks: ['newMenu/taxFinance', 'vendors'] }), new HtmlWebpackPlugin({ title: '政府扶持', filename: 'html/newMenu/governmentSupport.html', template: './template/newMenu/loading/governmentSupport.html', chunks: ['newMenu/governmentSupport', 'vendors'] }), new HtmlWebpackPlugin({ title: '在线评估', filename: 'html/newMenu/assessment.html', template: './template/newMenu/loading/assessment.html', chunks: ['newMenu/assessment', 'vendors'] }), new HtmlWebpackPlugin({ title: '邀请好友', filename: 'html/newMenu/Invitation.html', template: './template/newMenu/landingPage/Invitation.html', chunks: ['newMenu/Invitation', 'vendors'] }), new HtmlWebpackPlugin({ title: '优惠活动', filename: 'html/newMenu/invRegister.html', template: './template/newMenu/landingPage/InvRegister.html', chunks: ['newMenu/invRegister', 'vendors'] }), new HtmlWebpackPlugin({ title: '视频列表', filename: 'html/newMenu/video.html', template: './template/video.html', chunks: ['newMenu/video', 'vendors'] }), new HtmlWebpackPlugin({ title: '技淘视频', filename: 'html/newMenu/videoDetail.html', template: './template/videoDetail.html', chunks: ['newMenu/videoDetail', 'vendors'] }), new HtmlWebpackPlugin({ title: '技淘社区', filename: 'html/newMenu/special.html', template: './template/newMenu/special.html', chunks: ['newMenu/special', 'vendors'] }), new HtmlWebpackPlugin({ title: '技淘社区详情', filename: 'html/newMenu/specialDetail.html', template: './template/newMenu/specialDetail.html', chunks: ['newMenu/specialDetail', 'vendors'] }), ]; if (!isDev) { //这个使用uglifyJs压缩你的js代码 plugins.unshift(new webpack.DefinePlugin({ "process.env": { NODE_ENV: JSON.stringify("production") } })); plugins.unshift(new webpack.optimize.UglifyJsPlugin({ minimize: true, compress: { warnings: true } })); } let staticHost = 'http://172.16.1.187'; switch (argv.env.deploy) { case 'test': staticHost = 'http://statics.jishutao.com'; break; case 'prod': staticHost = 'http://js.junbangjishu.com'; break; default: break; } staticHost = staticHost + '/portal/' + version + '/'; return { entry: isWatch ? entries.watch : entries.prod, output: { path: path.resolve(__dirname, './build/' + argv.env.deploy + '/' + version), filename: '[name].js', publicPath: staticHost, chunkFilename: 'chunks/[name].[hash:8].js' }, module: require('./webpack/module.config.js')(theme), resolve: { extensions: ['.js', '.jsx'], alias: { 'js': __dirname + '/src/js', 'css': __dirname + '/src/css', 'imgs': __dirname + '/img', } }, plugins: plugins, devServer: { disableHostCheck: true, host: '172.16.1.187', port: 80, allowedHosts: ['192.168.0.222', '192.168.0.99', '192.168.0.20','192.168.0.17'], headers: { "Access-Control-Allow-Origin": "*" } } }; })();