UNPKG

2.57 kBJavaScriptView Raw
1'use strict'
2
3const fs = require('fs')
4const paths = require('./paths')
5const getEnv = require('./env')
6const { ensureSlash, camelName } = require('../libs/utils')
7const defConf = require('./default')
8const maraConf = require(paths.marauder)
9const pkgName = require(paths.packageJson).name
10const maraVersion = require(paths.ownPackageJson).version
11const useTypeScript = fs.existsSync(paths.tsConfig)
12
13function getServedPath(publicUrl) {
14 // 强制以 / 结尾,为了兼容 publicPath: '.'
15 return publicUrl ? ensureSlash(publicUrl, true) : '/'
16}
17
18const publicPath = getServedPath(maraConf.publicPath)
19const publicDevPath = getServedPath(maraConf.publicDevPath)
20
21module.exports = {
22 // 为了防止不同文件夹下的同名资源文件冲突
23 // 资源文件不提供 hash 修改权限
24 hash: {
25 main: true,
26 chunk: true,
27 assets: true
28 },
29 version: maraVersion,
30 debug: maraConf.debug,
31 library: {
32 root: 'MyLibrary',
33 amd: pkgName,
34 commonjs: pkgName
35 },
36 assetsDir: 'static',
37 // 编译配置
38 compiler: Object.assign({}, defConf.compiler, maraConf.compiler),
39 entry: defConf.esm.entry,
40 // 通知 babel 编译 node_module 里额外的模块
41 esm: defConf.esm,
42 // 打包 dll
43 vendor: [],
44 paths: paths,
45 useTypeScript,
46 build: {
47 env: getEnv(publicPath.slice(0, -1)),
48 assetsPublicPath: publicPath,
49 // Run the build command with an extra argument to
50 // View the bundle analyzer report after build finishes:
51 // `npm run build --report`
52 // Set to `true` or `false` to always turn it on or off
53 bundleAnalyzerReport: process.env.npm_config_report,
54 // upload bundle use ftp
55 // `npm run build <page> --ftp [namespace]`
56 // Set to `true` or `false` to always turn it on or off
57 uploadFtp: process.env.npm_config_ftp,
58 testDeploy: process.env.npm_config_test
59 },
60 dev: {
61 env: getEnv(publicDevPath.slice(0, -1)),
62 port: defConf.dev.port,
63 assetsPublicPath: publicDevPath,
64 proxyTable: {},
65 // CSS Sourcemaps off by default because relative paths are "buggy"
66 // with this option, according to the CSS-Loader README
67 // (https://github.com/webpack/css-loader#sourcemaps)
68 // In our experience, they generally work as expected,
69 // just be aware of this issue when enabling this option.
70 cssSourceMap: false
71 },
72 ftp: Object.assign({}, defConf.ftp, maraConf.ftp),
73 ciConfig: Object.assign({}, defConf.ciConfig, maraConf.ciConfig),
74 // hybrid 项目配置,存在此属性时,将会生成 zip 包
75 hybrid: defConf.hybrid,
76 postcss: defConf.postcss
77}