Use a single config object for recipe-client dependencies.

This commit is contained in:
Michael Kelly 2017-07-11 10:57:46 -07:00
Родитель 5ae3f933b5
Коммит 1a7b6d5f92
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 972176E09570E68A
2 изменённых файлов: 44 добавлений и 56 удалений

Просмотреть файл

@ -38,20 +38,22 @@ To add a dependency:
bugs from downloading newer versions of libraries that we haven't tested
the add-on against yet.
2. Add the dependency to ``recipe-client-addon/webpack.config.js`` using the
``libraryConfig`` function:
2. Add the dependency to ``recipe-client-addon/webpack.config.js`` as an entry
point:
.. code-block:: javascript
module.exports = [
// First argument is the name to export the library under
// Second argument is a path to the library's folder in node_modules
libraryConfig("ajv", "./node_modules/ajv"),
];
module.exports = {
entry: {
// The key is the name to export the library under
// The value is the path to the library's folder in node_modules
ajv: "./node_modules/ajv",
},
};
3. Re-build the vendor directory via ``npm run build``. Ensure that a
``libraryName_LICENSE`` file was generated withing ``vendor`` so that we have
licensing information for our dependencies.
3. Re-build the vendor directory via ``npm run build``. Ensure that licensing
info for the library was added to the ``LICENSE_THIRDPARTY`` file generated
within ``vendor`` so that we have licensing information for our dependencies.
.. note::

Просмотреть файл

@ -3,52 +3,38 @@ var path = require("path");
var ConcatSource = require("webpack-sources").ConcatSource;
var LicenseWebpackPlugin = require("license-webpack-plugin");
/**
* Create a webpack config object for a library. The compiled library will be
* output to the vendor directory.
*
* @param {String} name
* Library name. This generally should match the name used on npm.
* @param {String} entryPoint
* Path to the entry point of the library. Webpack can handle directories with
* a package.json file, so normally this is "./node_modules/libname".
*/
function libraryConfig(name, entryPoint) {
return {
context: __dirname,
entry: {
[name]: entryPoint,
},
output: {
path: path.resolve(__dirname, "vendor/"),
filename: "[name].js",
library: name,
libraryTarget: "this",
},
plugins: [
/**
* Plugin that appends "this.EXPORTED_SYMBOLS = ["libname"]" to assets
* output by webpack. This allows built assets to be imported using
* Cu.import.
*/
function ExportedSymbols() {
this.plugin("emit", function(compilation, callback) {
const assetName = `${name}.js`;
module.exports = {
context: __dirname,
entry: {
mozjexl: "./node_modules/mozjexl/",
},
output: {
path: path.resolve(__dirname, "vendor/"),
filename: "[name].js",
library: "[name]",
libraryTarget: "this",
},
plugins: [
/**
* Plugin that appends "this.EXPORTED_SYMBOLS = ["libname"]" to assets
* output by webpack. This allows built assets to be imported using
* Cu.import.
*/
function ExportedSymbols() {
this.plugin("emit", function(compilation, callback) {
for (const libraryName in compilation.entrypoints) {
const assetName = `${libraryName}.js`; // Matches output.filename
compilation.assets[assetName] = new ConcatSource(
compilation.assets[assetName],
`this.EXPORTED_SYMBOLS = ["${name}"];`
`this.EXPORTED_SYMBOLS = ["${libraryName}"];` // Matches output.library
);
callback();
});
},
new LicenseWebpackPlugin({
pattern: /^(MIT|ISC|MPL.*|Apache.*|BSD.*)$/,
filename: `${name}_LICENSE`,
}),
],
};
}
module.exports = [
libraryConfig("mozjexl", "./node_modules/mozjexl"),
];
}
callback();
});
},
new LicenseWebpackPlugin({
pattern: /^(MIT|ISC|MPL.*|Apache.*|BSD.*)$/,
filename: `LICENSE_THIRDPARTY`,
}),
],
};