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

External dependencies #145

Closed
wants to merge 8 commits into from
Closed
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
46 changes: 33 additions & 13 deletions lib/service-worker-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ const mergeTrees = require('broccoli-merge-trees');
const path = require('path');
const rollupReplace = require('rollup-plugin-replace');
const uglify = require('broccoli-uglify-sourcemap');
const resolve = require('rollup-plugin-node-resolve');
const includePaths = require('rollup-plugin-includepaths')
const commonJs = require('rollup-plugin-commonjs');

const TREE_FOR_METHODS = {
'service-worker': 'treeForServiceWorker',
'service-worker-registration': 'treeForServiceWorkerRegistration'
"service-worker": "treeForServiceWorker",
"service-worker-registration": "treeForServiceWorkerRegistration"
};

const ENTRY_POINT_FILENAMES = {
'service-worker': 'sw.js',
'service-worker-registration': 'sw-registration.js'
"service-worker": "sw.js",
"service-worker-registration": "sw-registration.js"
};

module.exports = class ServiceWorkerBuilder {
Expand All @@ -41,7 +44,7 @@ module.exports = class ServiceWorkerBuilder {
return trees.concat(pluginTree);
}

return trees
return trees;
}, []);
}

Expand All @@ -61,7 +64,7 @@ module.exports = class ServiceWorkerBuilder {

if (tree) {
return new Funnel(tree, {
destDir: plugin.pkg.name + '/' + type
destDir: plugin.pkg.name + "/" + type
});
}
}
Expand All @@ -72,7 +75,7 @@ module.exports = class ServiceWorkerBuilder {

let registrationDistPath = this.options.registrationDistPath;
let treeDistPath = treeName;
if (treeName === 'sw-registration.js' && registrationDistPath) {
if (treeName === "sw-registration.js" && registrationDistPath) {
treeDistPath = path.join(registrationDistPath, treeName);
}

Expand All @@ -84,7 +87,7 @@ module.exports = class ServiceWorkerBuilder {
}

_rollupTree(tree, entryFile, destFile) {
let rollupReplaceConfig = {
const rollupReplaceConfig = {
include: [
'/**/ember-service-worker/**/*.js',
// same as above but for windows paths like D:\my-ember\ember-service-worker\whatever\sw.js; which are updated before this step to D:/my-ember/ember-service/worker/whatever/sw.js
Expand All @@ -96,16 +99,29 @@ module.exports = class ServiceWorkerBuilder {
ROOT_URL: this.options.rootURL
};

const includePathOptions = {
extensions: ['.js', '.json']
}

return new Rollup(tree, {
inputFiles: '**/*.js',
inputFiles: "**/*.js",
rollup: {
input: entryFile,
output: {
file: destFile || entryFile,
format: 'iife',
exports: 'none',
},
exports: 'none',
plugins: [
commonJs({
include: 'node_modules/**',
}),
resolve({
module: true,
jsnext: true,
browser: true,
}),
includePaths(includePathOptions),
rollupReplace(rollupReplaceConfig)
]
}
Expand All @@ -116,14 +132,18 @@ module.exports = class ServiceWorkerBuilder {
if (this.options.minifyJS && this.options.minifyJS.enabled) {
let options = this.options.minifyJS.options || {};
options.sourceMapConfig = this.options.sourcemaps;
return uglify(tree, options);
return uglify(tree, options);
}

return tree;
}

_babelTranspile(tree) {
let emberCliBabel = this.app.project.addons.filter((a) => a.name === 'ember-cli-babel')[0];
return emberCliBabel.transpileTree(tree, { 'ember-cli-babel': { compileModules: false } });
return emberCliBabel.transpileTree(tree,
{
'ember-cli-babel': { compileModules: false},
}
);
}
}
};
Loading