2017-04-12 6 views
0

구성 파일에 webpack dev 구성이 있습니다. 프로덕션 모드 (abc.bundle.js, cde.bundle)에서 실행할 때 여러 번들 파일을 가져올 수 있습니다. js). 그러나 개발 모드에서 동일한 것을 얻지는 않습니다. 개발 모드에서 'main.bundle.js'만 얻습니다. 개발 모드에 대한Webpack 개발 모드에서 여러 번들 파일을 만들지 않습니다.

  var path = require('path'); 
      var webpack = require('webpack'); 
      var HtmlWebpackPlugin = require('html-webpack-plugin'); 
      var AppCachePlugin = require('appcache-webpack-plugin'); 

      var appConfig = require('./config.js'); 
console.log("appConfig is ->>>", appConfig); 
var appPort = appConfig.APP_PORT; //Port on which the application is running 

process.noDeprecation = true; 
module.exports = function(options) { 
var entry, jsLoaders, plugins, cssLoaders, devtool; 
console.log('options webconfig-->', options, 'directory name', __dirname); 

// If production is true 
if (options.prod) { 
console.log('production minifcation'); 
// Entry 
entry = { 
    veris: './js/abc.js', 
    au680: './js/cde.js', 
}; 


// Plugins 
plugins = [ // Plugins for Webpack 
    new webpack.DefinePlugin({ 
    'process.env': { 
     'NODE_ENV': JSON.stringify('production') 
    } 
    }), 
    new webpack.optimize.UglifyJsPlugin({ 
    minimize: true 
    }) 

]; 

// If app is in development 
} else { 
devtool = 'source-map'; 
// Entry 
entry = [ 
    "webpack-dev-server/client?http://0.0.0.0:" + appPort, // Needed for hot reloading 
    "webpack/hot/only-dev-server", // See above 
    //path.resolve(__dirname,'./js/app') // Start with js/app.js... 
    './js/abc.js', 
    './js/cde.js' 
]; 

// Only plugin is the hot module replacement plugin 
plugins = [ 
    new webpack.DefinePlugin({ 
    'process.env': { 
     'NODE_ENV': JSON.stringify('development') 
    } 
    }), 
    new webpack.HotModuleReplacementPlugin() // Make hot loading work, 
] 
} 

return { 
devtool: devtool, 
entry: entry, 
output: { // Compile into js/build.js 
    path: path.resolve(__dirname, 'build'), 
    filename: '[name].bundle.js' 
}, 
module: { 
    rules: [{ 
    test: /\.js$/, // Transform all .js files required somewhere within an entry point... 
    loader: 'babel-loader', // ...with the specified loaders... 
    exclude: /node_modules/, 
    query: { 
     presets: ['es2015', 'react', 'stage-2'] 
    } 

    }, { 
    test: /\.css$/, // Transform all .css files required somewhere within an entry point... 
    use: [{ 
     loader: 'style-loader' 
     }, { 
     loader: 'css-loader' 
     }, { 
     loader: 'postcss-loader' 
     }, { 
     loader: 'sass-loader' 
     }] // ...with PostCSS 
    }, { 
    test: /\.jpe?g$|\.gif$|\.png$/i, 
    loader: "url-loader?limit=100000" 
    }, { 
    test: /\.(woff|woff2|eot|ttf|svg)$/, 
    loader: 'url-loader?limit=100000' 
    }] 
}, 
plugins: plugins, 
target: "web", // Make web variables accessible to webpack, e.g. window 
stats: false, // Don't show stats in the console 
node: { 
    fs: "empty" 
} 
} 
} 

답변

1

귀하의 진입 점에는 다음이 포함

entry = [ 
    "webpack-dev-server/client?http://0.0.0.0:" + appPort, // Needed for hot reloading 
    "webpack/hot/only-dev-server", // See above 
    //path.resolve(__dirname,'./js/app') // Start with js/app.js... 
    './js/abc.js', 
    './js/cde.js' 
]; 

당신은 당신이 생산처럼지도에이 변환해야합니다

entry = { 
    main: [ 
    "webpack-dev-server/client?http://0.0.0.0:" + appPort, // Needed for hot reloading 
    "webpack/hot/only-dev-server" // See above 
    ], 
    //path.resolve(__dirname,'./js/app') // Start with js/app.js... 
    veris: './js/abc.js', 
    au680: './js/cde.js' 
}; 
+0

감사합니다 .IT 근무 @andrie! – stack26