-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): cli 支持事件 && 小程序编译配置向 H5 看齐
- Loading branch information
Showing
11 changed files
with
1,069 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,32 @@ | ||
import * as path from 'path' | ||
import * as webpack from 'webpack' | ||
|
||
import { IBuildConfig } from './utils/types' | ||
import { printBuildError, bindProdLogger } from './utils/logHelper' | ||
import MiniPlugin, { Targets } from './plugins/MiniPlugin' | ||
import { MINI_APP_FILES, BUILD_TYPES } from './utils/constants' | ||
import buildConf from './webpack/build.conf' | ||
|
||
const extensions = ['.ts', '.tsx', '.js', '.jsx'] | ||
|
||
const globalObjectMap = { | ||
[BUILD_TYPES.WEAPP]: 'wx', | ||
[BUILD_TYPES.ALIPAY]: 'my', | ||
[BUILD_TYPES.SWAN]: 'swan', | ||
[BUILD_TYPES.QQ]: 'qq', | ||
[BUILD_TYPES.TT]: 'tt' | ||
const customizeChain = (chain, customizeFunc: Function) => { | ||
if (customizeFunc instanceof Function) { | ||
customizeFunc(chain, webpack) | ||
} | ||
} | ||
|
||
export default function build (config: IBuildConfig) { | ||
const compilePlugins = config.plugins | ||
const { babel } = compilePlugins | ||
const webpackConfig = { | ||
mode: config.isWatch ? 'development' : 'production', | ||
devtool: false, | ||
entry: config.entry, | ||
output: { | ||
filename: '[name].js', | ||
publicPath: '/', | ||
path: config.outputDir, | ||
globalObject: globalObjectMap[config.buildAdapter] | ||
}, | ||
resolve: { | ||
extensions | ||
}, | ||
target: Targets[config.buildAdapter], | ||
optimization: { | ||
runtimeChunk: { | ||
name: 'runtime' | ||
}, | ||
splitChunks: { | ||
chunks: 'all', | ||
maxInitialRequests: Infinity, | ||
minSize: 0, | ||
name: 'vendors' | ||
} | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.(tsx?|jsx?)$/, | ||
use: [{ | ||
loader: path.resolve(__dirname, './loaders/fileParseLoader'), | ||
options: { | ||
babel, | ||
designWidth: config.designWidth, | ||
deviceRatio: config.deviceRatio, | ||
buildAdapter: config.buildAdapter, | ||
constantsReplaceList: config.constantsReplaceList | ||
} | ||
}, { | ||
loader: path.resolve(__dirname, './loaders/wxTransformerLoader'), | ||
options: { | ||
buildAdapter: config.buildAdapter | ||
} | ||
}] | ||
}, | ||
{ | ||
test: /\.(scss|wxss|acss|ttss|acss|)$/, | ||
include: /src/, | ||
use: [ | ||
{ | ||
loader: require.resolve('file-loader'), | ||
options: { | ||
useRelativePath: true, | ||
name: `[path][name]${MINI_APP_FILES[config.buildAdapter].STYLE}`, | ||
context: config.sourceDir | ||
} | ||
}, | ||
{ | ||
loader: require.resolve('sass-loader'), | ||
options: { | ||
export default function build (appPath: string, config: IBuildConfig, mainBuilder) { | ||
const mode = 'development' | ||
return new Promise((resolve, reject) => { | ||
const webpackChain = buildConf(appPath, mode, config) | ||
|
||
}, | ||
}, | ||
], | ||
} | ||
] | ||
}, | ||
plugins: [ | ||
new MiniPlugin({ | ||
buildAdapter: config.buildAdapter, | ||
constantsReplaceList: config.constantsReplaceList | ||
}) | ||
] | ||
} | ||
customizeChain(webpackChain, config.webpackChain) | ||
const webpackConfig = webpackChain.toConfig() | ||
|
||
const compiler = webpack(webpackConfig) | ||
bindProdLogger(compiler) | ||
const compiler = webpack(webpackConfig) | ||
bindProdLogger(compiler) | ||
|
||
compiler.run((err) => { | ||
if (err) { | ||
printBuildError(err) | ||
} | ||
compiler.run((err) => { | ||
if (err) { | ||
printBuildError(err); | ||
return reject(err) | ||
} | ||
resolve() | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.