@gdjiami/cli
Version:
CLI for build front end project.
68 lines (67 loc) • 2.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
/**
* 开发环境配置
*/
var webpack_1 = tslib_1.__importDefault(require("webpack"));
var path_1 = tslib_1.__importDefault(require("path"));
var fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
var utils_1 = require("../utils");
var HtmlInjectedDllReferences_1 = tslib_1.__importDefault(require("./plugins/HtmlInjectedDllReferences"));
var CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
var MiniCssExtractPlugin = require('mini-css-extract-plugin');
var configure = function (enviroments, pkg, paths, argv) {
var isIE8 = argv.jmOptions.ie8;
function isSupportDll() {
if (enviroments.raw.DISABLE_DLL === 'true' || isIE8) {
return false;
}
return fs_extra_1.default.existsSync(paths.appDllHash);
}
var supportDll = isSupportDll();
if (supportDll) {
utils_1.message.info('DllReference Turned on');
}
if (isIE8) {
utils_1.message.info('HotReload Disabled');
}
var name = argv.name;
var filePrefix = name ? name + "_" : '';
return {
entry: {},
devtool: enviroments.raw.SOURCE_MAP === 'false'
? false
: enviroments.raw.EVAL === 'true'
? 'cheap-module-eval-source-map'
: 'cheap-module-source-map',
module: {
rules: [],
},
plugins: [
!isIE8 && new webpack_1.default.HotModuleReplacementPlugin(),
isIE8 &&
new MiniCssExtractPlugin({
filename: "static/css/" + filePrefix + "[name].css?[contenthash:8]",
chunkFilename: "static/css/" + filePrefix + "[name].chunk.css?[contenthash:8]",
}),
// 在windows下大小写是不敏感的,这在其他端会导致问题
new CaseSensitivePathsPlugin(),
supportDll &&
new webpack_1.default.DllReferencePlugin({
context: paths.appSrc,
manifest: path_1.default.join(paths.appCache, 'dll.json'),
name: 'dll',
}),
supportDll && new HtmlInjectedDllReferences_1.default('dll'),
].filter(Boolean),
optimization: {
// 使用可读性更高的模块标识符, 在开发环境更容易debug, 取代NamedModulesPlugin
// 默认在development环境下是开启的
namedModules: true,
namedChunks: true,
noEmitOnErrors: true,
},
};
};
exports.default = configure;