Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
${SCHEMA_VAR} = ${JSON.stringify(mockData)};
} catch(err) {
console.warn('Inject schema data with error', err);
}
`;
} catch (err) {
throw new Error('Please check schema/mock-data.json is a valid JSON string.');
}
}
if (injectSchemaMockData) {
args.unshift(injectSchemaMockData);
}
args.unshift(ConcatSource); // firstArg for apply
const app = new (ConcatSource.bind.apply(ConcatSource, args))();
compilation.assets['app.js'] = app;
global.AppJSContent = app.source();
});
});
compilation.hooks.optimizeAssets.tap('MiniAppPlugin', () => {
const args = Object.values(compilation.assets);
// polyfill global context
args.unshift(new ConcatSource(globalPolyfills.join('')));
args.unshift(ConcatSource);
const app = new (ConcatSource.bind.apply(ConcatSource, args))();
// 删除原 assets
Object.keys(compilation.assets).forEach((key) => {
delete compilation.assets[key];
});
// 增加 app.js
// wrapper for app.js
compilation.assets['app.js'] = app;
global.AppJSContent = app.source();
let injectSchemaMockData;
const mockDataPath = join(compiler.context, 'schema/mock-data.json');
if (existsSync(mockDataPath)) {
try {
const mockData = JSON.parse(readFileSync(mockDataPath));
compilation.hooks.optimizeAssets.tap('MiniAppPlugin', () => {
const args = Object.values(compilation.assets);
// polyfill global context
args.unshift(new ConcatSource(globalPolyfills.join('')));
args.unshift(ConcatSource);
const app = new (ConcatSource.bind.apply(ConcatSource, args))();
// 删除原 assets
Object.keys(compilation.assets).forEach((key) => {
delete compilation.assets[key];
});
compilation.assets['app.js'] = app;
compilation.assets['app.web.js'] = new ConcatSource(
'__register_pages__(function(require){',
app,
'});',
);
});
});