index.js (2369B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ 4 5 const path = require("path"); 6 const util = require("util"); 7 const _ = require("lodash"); 8 const webpack = require("webpack"); 9 10 const TARGET_NAME = "webpack3-babel6"; 11 12 module.exports = exports = async function(tests, dirname) { 13 const fixtures = []; 14 for (const [name, input] of tests) { 15 if (/typescript-/.test(name)) { 16 continue; 17 } 18 19 const testFnName = _.camelCase(`${TARGET_NAME}-${name}`); 20 const evalMaps = name.match(/-eval/); 21 const babelEnv = !name.match(/-es6/); 22 const babelModules = name.match(/-cjs/); 23 24 console.log(`Building ${TARGET_NAME} test ${name}`); 25 26 const scriptPath = path.join(dirname, "output", TARGET_NAME, `${name}.js`); 27 const result = await util.promisify(webpack)({ 28 context: path.dirname(input), 29 entry: `./${path.basename(input)}`, 30 output: { 31 path: path.dirname(scriptPath), 32 filename: path.basename(scriptPath), 33 34 devtoolModuleFilenameTemplate: `${TARGET_NAME}://./${name}/[resource-path]`, 35 36 libraryTarget: "var", 37 library: testFnName, 38 libraryExport: "default" 39 }, 40 devtool: evalMaps ? "eval-source-map" : "source-map", 41 module: { 42 loaders: [ 43 { 44 test: /\.js$/, 45 exclude: /node_modules/, 46 loader: require.resolve("babel-loader"), 47 options: { 48 babelrc: false, 49 presets: [ 50 babelEnv 51 ? [ 52 require.resolve("babel-preset-env"), 53 { modules: babelModules ? "commonjs" : false } 54 ] 55 : null 56 ].filter(Boolean), 57 plugins: [ 58 require.resolve("babel-plugin-transform-flow-strip-types"), 59 require.resolve("babel-plugin-transform-class-properties") 60 ] 61 } 62 } 63 ].filter(Boolean) 64 } 65 }); 66 67 fixtures.push({ 68 name, 69 testFnName: testFnName, 70 scriptPath, 71 assets: [scriptPath, evalMaps ? null : `${scriptPath}.map`].filter( 72 Boolean 73 ) 74 }); 75 } 76 77 return { 78 target: TARGET_NAME, 79 fixtures 80 }; 81 };