import webpack from 'webpack' ; import { getCwdPath , loggerTiming , loggerError , loggerInfo , loggerSuccess } from '@/util' ; import { loadFile } from '@/util/file' ; import { getProConfig } from './webpack.pro.config' ; import { getDevConfig } from './webpack.dev.config' ; import { getCssLoaders , getCssPlugin } from './css.config' ; import cacheConfig from './cache.config' ; const WebpackDevServer = require ( 'webpack-dev-server/lib/Server' ) ; description param { * } webpack return { * } export const buildWebpack = ( ) => { loggerTiming ( 'WEBPACK BUILD' ) ; const rewriteConfig = loadFile < any > ( getCwdPath ( './cli.config.json' ) , false ) ; const webpackConfig = getProConfig ( { ... rewriteConfig , cssLoader : getCssLoaders ( false ) , ... getCssPlugin ( ) , ... cacheConfig } ) ; const compiler = webpack ( webpackConfig ) ; try { compiler . run ( ( err , stats ) => { if ( err ) { loggerError ( err ) ; } else { loggerSuccess ( 'WEBPACK SUCCESS!' ) ; } compiler . close ( ( ) => { loggerInfo ( 'WEBPACK GENERATE CACHE' ) ; } ) ; loggerTiming ( 'WEBPACK BUILD' , false ) ; } ) ; } catch ( error ) { loggerError ( error ) ; } } ; description param { * } webpack return { * } export const devServerWebpack = ( ) => { loggerTiming ( 'WEBPACK DEV' ) ; const rewriteConfig = loadFile < any > ( getCwdPath ( './cli.config.json' ) , false ) ; const webpackConfig = getDevConfig ( { ... rewriteConfig , cssLoader : getCssLoaders ( true ) , ... cacheConfig } ) ; const compiler = webpack ( webpackConfig ) ; const devServerOptions = { stats : 'errors-only' , contentBase : 'dist' , hot : true , disableHostCheck : true , historyApiFallback : true , compress : true , open : true } ; const server = new WebpackDevServer ( compiler , devServerOptions ) ; server . listen ( 8080 , "0.0.0.0" , ( ) => { loggerTiming ( 'WEBPACK DEV' , false ) ; loggerInfo ( 'Starting server on http://localhost:8000' ) ; } ) ; } ;