Skip to content

Commit

Permalink
Work on stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
thecrypticace committed Sep 11, 2021
1 parent 9f967cd commit d895c3f
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 43 deletions.
1 change: 1 addition & 0 deletions src/Mix.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ class Mix {
* Determine if the given config item is truthy.
*
* @param {string} tool
* @deprecated Please check the mix config directly instead
*/
isUsing(tool) {
// @ts-ignore
Expand Down
25 changes: 18 additions & 7 deletions src/components/Alias.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
module.exports = class Alias {
const { Component } = require('./Component');

module.exports = class Alias extends Component {
/** @type {Record<string, string>} */
aliases = {};

/**
* Add resolution aliases to webpack's config
*
* @param {Record<string,string>} paths
* @param {Record<string, string>} paths
*/
register(paths) {
/** @type {Record<string, string>} */
this.aliases = { ...(this.aliases || {}), ...paths };
this.aliases = { ...this.aliases, ...paths };
}

webpackConfig(webpackConfig) {
webpackConfig.resolve.alias = webpackConfig.resolve.alias || {};
/**
*
* @param {import('webpack').Configuration} config
*/
webpackConfig(config) {
config.resolve = config.resolve || {};
config.resolve.alias = config.resolve.alias || {};

for (const [alias, path] of Object.entries(this.aliases)) {
webpackConfig.resolve.alias[alias] = Mix.paths.root(path);
config.resolve.alias[alias] = this.mix.paths.root(path);
}

return config;
}
};
26 changes: 14 additions & 12 deletions src/components/Autoload.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
class Autoload {
const { Component } = require('./Component');

class Autoload extends Component {
/** @type {Record<string, string | string[]>} */
aliases = {};

/**
* Register the component.
*
* @param {Object} libs
* @return {void}
* @param {Record<string, string | string[]>} libs
*/
register(libs) {
let aliases = {};

Object.keys(libs).forEach(library => {
[].concat(libs[library]).forEach(alias => {
aliases[alias] = library.includes('.') ? library.split('.') : library;
});
});
for (let [library, aliases] of Object.entries(libs)) {
const lib = library.includes('.') ? library.split('.') : [library];

this.aliases = aliases;
for (const alias of Array.isArray(aliases) ? aliases : [aliases]) {
this.aliases[alias] = lib;
}
}
}

/**
Expand All @@ -23,7 +25,7 @@ class Autoload {
webpackPlugins() {
let webpack = require('webpack');

return new webpack.ProvidePlugin(this.aliases);
return [new webpack.ProvidePlugin(this.aliases)];
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/components/AutomaticComponent.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @deprecated Instead extend `Component` and set `passive` to `true`
**/
class AutomaticComponent {
/**
* Create a new component instance.
Expand Down
11 changes: 5 additions & 6 deletions src/components/Before.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
class Before {
const { Component } = require('./Component');

class Before extends Component {
/**
* Register the component.
*
* @param {Function} callback
* @return {void}
* @param {() => void | Promise<void>} callback
*/
register(callback) {
Mix.listen('init', callback);
this.mix.listen('init', callback);
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/components/CssWebpackConfig.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
let semver = require('semver');
let mapValues = require('lodash').mapValues;
let AutomaticComponent = require('./AutomaticComponent');
let { Component } = require('./Component');
let MiniCssExtractPlugin = require('mini-css-extract-plugin');
let PostCssPluginsFactory = require('../PostCssPluginsFactory');

class CssWebpackConfig extends AutomaticComponent {
class CssWebpackConfig extends Component {
passive = true;

dependencies() {
this.requiresReload = true;

Expand Down
31 changes: 19 additions & 12 deletions src/components/Notifications.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
let AutomaticComponent = require('./AutomaticComponent');
const { Component } = require('./Component');

class Notifications extends Component {
passive = true;

class Notifications extends AutomaticComponent {
/**
* webpack plugins to be appended to the master config.
*/
webpackPlugins() {
if (Mix.isUsing('notifications')) {
let WebpackNotifierPlugin = require('webpack-notifier');
if (!this.mix.config.notifications) {
return;
}

return new WebpackNotifierPlugin({
appID: 'Laravel Mix',
let WebpackNotifierPlugin = require('webpack-notifier');

title: 'Laravel Mix',
alwaysNotify: Config.notifications.onSuccess,
timeout: false,
hint: process.platform === 'linux' ? 'int:transient:1' : undefined,
contentImage: Mix.paths.root('node_modules/laravel-mix/icons/laravel.png')
});
}
return new WebpackNotifierPlugin({
appID: 'Laravel Mix',

title: 'Laravel Mix',
alwaysNotify: this.mix.config.notifications.onSuccess,
timeout: false,
hint: process.platform === 'linux' ? 'int:transient:1' : undefined,
contentImage: this.mix.paths.root(
'node_modules/laravel-mix/icons/laravel.png'
)
});
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/webpackPlugins/MixDefinitionsPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ let expand = require('dotenv-expand');
class MixDefinitionsPlugin {
/**
*
* @param {string} [envPath]
* @param {string} envPath
* @param {Record<string, string>} [additionalEnv]
*/
constructor(envPath = undefined, additionalEnv = {}) {
this.envPath = envPath || global.Mix.paths.root('.env');
constructor(envPath, additionalEnv = {}) {
this.envPath = envPath;
this.additionalEnv = additionalEnv;
}

Expand Down Expand Up @@ -75,7 +75,8 @@ class MixDefinitionsPlugin {
* @param {Record<string, string>} additionalEnv
*/
static build(additionalEnv) {
return new MixDefinitionsPlugin(undefined, additionalEnv).plugin;
return new MixDefinitionsPlugin(global.Mix.paths.root('.env'), additionalEnv)
.plugin;
}
}

Expand Down

0 comments on commit d895c3f

Please sign in to comment.