Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加对小程序项目的适配 #135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/recommended/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"devDependencies": {
"html-webpack-plugin": "3.2.0",
"webpack": "^4.0.0",
"webpack-cli": "^2.0.11",
"webpack-cli": "^3.1.1",
"webpack-dev-server": "^3.0.0"
},
"dependencies": {
Expand Down
23 changes: 21 additions & 2 deletions src/createConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,43 @@ const prepare = config => {
};

export const _createConfig = cacheDir => (settings, rawParentConfig) => {
const { hash, filename = [] } = settings;
const { hash, filename = [], libraryTarget = undefined } = settings;
const outputPath = path.join(cacheDir, hash);

const parentConfig = mapParentConfig(settings, prepare(rawParentConfig));

let dllExportNamePre = '';
let outputParams = {};
// 判断是否有设置一个暴露出的全局变量
/**
* libraryTarget == ”global“的时候存在一个问题,生成的dll文件是 window.vendor_hash = function(){}
* 正确应该是要生成 global.vendor_hash = function(){}
* 根据我的尝试 只要再设置一个 globalObject 就可以正确生成文件
* 另外 为了要适配小程序的使用,我在mainifest.json文件中 设置了变量名为 global.[name]_[hash]
*/
if (libraryTarget == 'global') {
dllExportNamePre = libraryTarget + '.';
outputParams = {
globalObject: libraryTarget, //全局对象配置
libraryTarget,
};
}

const ownConfig = {
context: settings.context,
entry: settings.entry,
plugins: [
...(settings.plugins || []),
new DllPlugin({
path: path.join(outputPath, '[name].manifest.json'),
name: '[name]_[chunkhash]',
name: dllExportNamePre + '[name]_[chunkhash]',
}),
],
output: {
filename: filename,
library: '[name]_[chunkhash]',
// ...outputParams,
...outputParams,
},
};

Expand Down