123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- const OpenBrowserPlugin = require('open-browser-webpack-plugin');
- const CopyWebpackPlugin = require('copy-webpack-plugin');
- const webpack = require('webpack');
- const path = require('path');
- const common = require('./webpack.common');
- const merge = require('webpack-merge');
- const configJSON = require('../config.json');
- const buildEntry = require('./buildEntry');
- const port = configJSON.devPort || 3006;
- const host = 'localhost';
- const fs = require('fs');
- module.exports = function(env, argv) {
- let { mode, buildPath, client = 'pc' } = env;
- if (client === 'mobile') {
- process.env.PROJECT_CLIENT = 'mobile';
- }
- buildPath = buildPath || configJSON.buildEntryPath || './src/*/*/*/*/index.js';
- let buildWithoutHTML = configJSON.buildWithoutHTML;
- buildWithoutHTML && typeof buildWithoutHTML === 'string' && (buildWithoutHTML = [buildWithoutHTML]);
- let devConfig = {
- mode,
- entry: {},
- output: {
- filename: '[name].js',
- path: path.resolve(__dirname, './dist'),
- publicPath: '/',
- library: '[name]',
- libraryTarget: 'umd',
- chunkFilename: '[name].js'
- },
- devtool: 'source-map',
- devServer: {
- contentBase: path.join(__dirname, '../src'),
- port,
- host: '0.0.0.0',
- inline: false,
- clientLogLevel: 'error',
- open: false,
- hot: true,
- lazy: false,
- historyApiFallback: {
-
- rewrites: { from: /./, to: '/404.html' }
- },
- overlay: {
-
- warnings: true,
- errors: true
- },
- stats: 'errors-only',
- proxy: {
-
- '/nccloud': {
- target: configJSON.proxy
- }
- }
- },
- plugins: [
- new webpack.DefinePlugin({
- NODE_ENV: JSON.stringify(mode),
- ISMA: configJSON.isMA,
- LOGIN_INFO: JSON.stringify(configJSON.directConnectInfo),
- MA_INFO: JSON.stringify(configJSON.maInfo)
- }),
- new webpack.NamedModulesPlugin(),
- new webpack.HotModuleReplacementPlugin(),
- new OpenBrowserPlugin({ url: `http://${host}:${port}/nccloud` })
- ]
- };
-
- let extendBuildEntryPath = configJSON.extendBuildEntryPath || [];
- let { entries: extendEntries, plugins: extendPlugins } = buildEntry({
- buildPath: extendBuildEntryPath,
- buildWithoutHTML,
- hash: false,
- mode,
- client,
- fse: true
- });
-
-
- let { entries, plugins, externals } = buildEntry({
- buildPath,
- buildWithoutHTML,
- hash: true,
- mode,
- client
- });
-
- Object.assign(entries, extendEntries);
- Object.assign(common.externals, externals);
- Object.assign(devConfig.entry, entries);
- devConfig.plugins.push(...plugins);
- devConfig = merge(common, devConfig);
- return devConfig;
- };
|