专栏名称: 前端大全
分享 Web 前端相关的技术文章、工具资源、精选课程、热点资讯
目录
相关文章推荐
简约小生活  ·  容易长肉的主食,不是米饭而是它,常吃等于喝油 ·  13 小时前  
简约小生活  ·  容易长肉的主食,不是米饭而是它,常吃等于喝油 ·  13 小时前  
简约小生活  ·  手上这块肉,一看就知身体好坏,很灵哦! ·  13 小时前  
简约小生活  ·  手上这块肉,一看就知身体好坏,很灵哦! ·  13 小时前  
脚本之家  ·  众多大厂 Vue3 项目放弃使用 ... ·  昨天  
惠山市场监管  ·  惠小特讲安全之乘坐过山车 ·  3 天前  
惠山市场监管  ·  惠小特讲安全之乘坐过山车 ·  3 天前  
51好读  ›  专栏  ›  前端大全

基于 webpack 的前后端分离开发环境实践

前端大全  · 公众号  · 前端  · 2017-08-27 20:30

正文

请到「今天看啥」查看全文


( config ) => ({

compiler_base_route : '/apps/' ,

compiler_public_path : '/static/' ,

compiler_fail_on_warning : false ,

compiler_hash_type : 'chunkhash' ,

compiler_devtool : false ,

compiler_stats : {

chunks : true ,

chunkModules : true ,

colors : true

}

})

}


project.config.js中的关键实现:


// project.config.js

const config = {

env : process . env . NODE_ENV || 'development' ,

// ----------------------------------

// Project Structure

// ----------------------------------

path_base : path . resolve ( __dirname , '..' ),

dir_client : 'src' ,

dir_dist : 'dist' ,

dir_public : 'public' ,

dir_server : 'server' ,

dir_test : 'tests' ,

// ----------------------------------

// Server Configuration

// ----------------------------------

server_host : ip . address (), // use string 'localhost' to prevent exposure on local network

server_port : process . env . PORT || 3000 ,

// ----------------------------------

// Compiler Configuration

// ----------------------------------

compiler_devtool : 'source-map' ,

compiler_hash_type : 'hash' ,

compiler_fail_on_warning : false ,

compiler_quiet : false ,

compiler_public_path : '/' ,

compiler_stats : {

chunks : false ,

chunkModules : false ,

colors : true

}

};

// 在此通过读取环境变量读取environments中对应的配置项,对前面的配置项进行覆盖

const environments = require ( './environments.config' )

const overrides = environments [ config . env ]

if ( overrides ) {

debug ( 'Found overrides, applying to default configuration.' )

Object . assign ( config , overrides ( config ))

} else {

debug ( 'No environment overrides found, defaults will be used.' )

}

module . exports = config


webpack.config.js中的关键实现:


const webpack = require ( 'webpack' )

const project = require ( './project.config' )

const debug = require ( 'debug' )( 'app:config:webpack' )

const UglifyJsParallelPlugin = require ( 'webpack-uglify-parallel' )

const __DEV__ = project . globals . __DEV__

const __PROD__ = project . globals . __PROD__

const webpackConfig = {

name : 'client' ,

target : 'web' ,

devtool : project . compiler_devtool ,

resolve : {

modules : [ project







请到「今天看啥」查看全文