Skip to content

Commit

Permalink
Allow for no mix.js() calls at all.
Browse files Browse the repository at this point in the history
This way, you can do mix.sass() only.
  • Loading branch information
JeffreyWay committed Jan 26, 2017
1 parent 4b44830 commit cbe95bf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "laravel-mix",
"version": "0.5.7",
"version": "0.5.8",
"description": "Laravel Mix is an elegant wrapper around Webpack for the 80% use case.",
"main": "src/index.js",
"scripts": {
Expand Down
25 changes: 12 additions & 13 deletions src/Mix.js
Expand Up @@ -18,6 +18,7 @@ class Mix {
this.notifications = true;
this.cssPreprocessor = false;
this.versioning = false;
this.js = [];
this.inProduction = process.env.NODE_ENV === 'production';
this.publicPath = './';
}
Expand Down Expand Up @@ -73,21 +74,19 @@ class Mix {
* Determine the Webpack entry file(s).
*/
entry() {
if (! this.js) {
throw new Error(
`Laravel Mix: You must call "mix.js()" once or more.`
);
}
let entry = { 'app': [] };

let entry = this.js.reduce((result, paths) => {
let name = paths.output.pathWithoutExt
.replace(this.publicPath, '')
.replace(/\\/g, '/');
if (this.js.length) {
entry = this.js.reduce((result, paths) => {
let name = paths.output.pathWithoutExt
.replace(this.publicPath, '')
.replace(/\\/g, '/');

result[name] = paths.entry.map(src => src.path);
result[name] = paths.entry.map(src => src.path);

return result;
}, {});
return result;
}, {});
}

if (this.cssPreprocessor) {
let stylesheets = this[this.cssPreprocessor].map(entry => entry.src.path);
Expand All @@ -96,7 +95,7 @@ class Mix {
entry[name] = entry[name].concat(stylesheets);
}

if (this.js.vendor) {
if (this.js.length && this.js.vendor) {
let vendorPath = (this.js.base + '/vendor').replace(this.publicPath, '');

entry[vendorPath] = this.js.vendor;
Expand Down
17 changes: 4 additions & 13 deletions test/mix.js
Expand Up @@ -10,21 +10,12 @@ test.afterEach('cleanup', t => {
});


test('that it throws an exception if mix.js() was not called', t => {
let error = t.throws(() => {
test('that it uses a default entry, if mix.js() is never called', t => {
mix.sass('sass/stub.scss', 'dist');
Mix.entry();
}, Error);

t.is(error.message, 'Laravel Mix: You must call "mix.js()" once or more.');

mix.reset();

t.notThrows(() => {
mix.js('js/stub.js', 'dist');
mix.sass('css/stub.css', 'dist');
Mix.entry();
}, Error);
t.deepEqual({
app: [path.resolve('sass/stub.scss')]
}, Mix.entry());
});


Expand Down

0 comments on commit cbe95bf

Please sign in to comment.