nav tabs on admin dashboard
This commit is contained in:
+3
-1
@@ -10,7 +10,9 @@ class Autoload {
|
||||
|
||||
Object.keys(libs).forEach(library => {
|
||||
[].concat(libs[library]).forEach(alias => {
|
||||
aliases[alias] = library.includes('.') ? library.split('.') : library;
|
||||
aliases[alias] = library.includes('.')
|
||||
? library.split('.')
|
||||
: library;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ class Coffee extends JavaScript {
|
||||
* Required dependencies for the component.
|
||||
*/
|
||||
dependencies() {
|
||||
return ['coffee-loader', 'coffeescript'].concat(super.dependencies());
|
||||
return ['coffee-loader', 'coffeescript'].concat();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+2
-2
@@ -8,7 +8,6 @@ let components = [
|
||||
'React',
|
||||
'Coffee',
|
||||
'TypeScript',
|
||||
'FastSass',
|
||||
'Less',
|
||||
'Sass',
|
||||
'Stylus',
|
||||
@@ -23,7 +22,8 @@ let components = [
|
||||
'Extract',
|
||||
'Notifications',
|
||||
'DisableNotifications',
|
||||
'PurifyCss'
|
||||
'PurifyCss',
|
||||
'DumpWebpackConfig'
|
||||
];
|
||||
|
||||
class ComponentFactory {
|
||||
|
||||
+87
-4
@@ -8,19 +8,83 @@ class Css extends AutomaticComponent {
|
||||
return [
|
||||
{
|
||||
test: /\.css$/,
|
||||
loaders: ['style-loader', 'css-loader']
|
||||
loaders: [
|
||||
'style-loader',
|
||||
{ loader: 'css-loader', options: { importLoaders: 1 } },
|
||||
{
|
||||
loader: 'postcss-loader',
|
||||
options: this.postCssOptions()
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
test: /\.s[ac]ss$/,
|
||||
test: /\.scss$/,
|
||||
exclude: this.excludePathsFor('sass'),
|
||||
loaders: ['style-loader', 'css-loader', 'sass-loader']
|
||||
loaders: [
|
||||
'style-loader',
|
||||
'css-loader',
|
||||
{
|
||||
loader: 'postcss-loader',
|
||||
options: this.postCssOptions()
|
||||
},
|
||||
{
|
||||
loader: 'sass-loader',
|
||||
options: {
|
||||
precision: 8,
|
||||
outputStyle: 'expanded'
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
test: /\.sass$/,
|
||||
exclude: this.excludePathsFor('sass'),
|
||||
loaders: [
|
||||
'style-loader',
|
||||
'css-loader',
|
||||
{
|
||||
loader: 'postcss-loader',
|
||||
options: this.postCssOptions()
|
||||
},
|
||||
{
|
||||
loader: 'sass-loader',
|
||||
options: {
|
||||
precision: 8,
|
||||
outputStyle: 'expanded',
|
||||
indentedSyntax: true
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
test: /\.less$/,
|
||||
exclude: this.excludePathsFor('less'),
|
||||
loaders: ['style-loader', 'css-loader', 'less-loader']
|
||||
loaders: [
|
||||
'style-loader',
|
||||
'css-loader',
|
||||
{
|
||||
loader: 'postcss-loader',
|
||||
options: this.postCssOptions()
|
||||
},
|
||||
'less-loader'
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
test: /\.styl(us)?$/,
|
||||
exclude: this.excludePathsFor('stylus'),
|
||||
loaders: [
|
||||
'style-loader',
|
||||
'css-loader',
|
||||
{
|
||||
loader: 'postcss-loader',
|
||||
options: this.postCssOptions()
|
||||
},
|
||||
'stylus-loader'
|
||||
]
|
||||
}
|
||||
];
|
||||
}
|
||||
@@ -37,6 +101,25 @@ class Css extends AutomaticComponent {
|
||||
? exclusions.details.map(preprocessor => preprocessor.src.path())
|
||||
: [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the appropriate postcss plugins for the compile.
|
||||
*/
|
||||
postCssOptions() {
|
||||
if (Mix.components.get('postCss')) {
|
||||
return {
|
||||
plugins: Mix.components.get('postCss').details[0].postCssPlugins
|
||||
};
|
||||
}
|
||||
|
||||
// If the user has a postcss.config.js file in their project root,
|
||||
// postcss-loader will automatically read and fetch the plugins.
|
||||
if (File.exists(Mix.paths.root('postcss.config.js'))) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return { plugins: Config.postCss };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Css;
|
||||
|
||||
+1
-1
@@ -114,7 +114,7 @@ class Example {
|
||||
*/
|
||||
babelConfig() {
|
||||
// Example:
|
||||
// return { presets: ['react'] };
|
||||
// return { presets: ['@babel/preset-react'] };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+94
-24
@@ -1,20 +1,41 @@
|
||||
let webpack = require('webpack');
|
||||
let webpackMerge = require('webpack-merge');
|
||||
|
||||
class Extract {
|
||||
/**
|
||||
* Create a new component instance.
|
||||
*/
|
||||
constructor() {
|
||||
this.entry = null;
|
||||
this.extractions = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* The name of the component.
|
||||
*
|
||||
* mix.extract() or mix.extractVendor()
|
||||
*/
|
||||
name() {
|
||||
return ['extract', 'extractVendors'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the component.
|
||||
*
|
||||
* @param {*} libs
|
||||
* @param {string} output
|
||||
*/
|
||||
register(libs, output) {
|
||||
register(libs = [], output) {
|
||||
// If the user provides an output path as the first argument, they probably
|
||||
// want to extract all node_module libraries to the specified file.
|
||||
if (
|
||||
arguments.length === 1 &&
|
||||
typeof libs === 'string' &&
|
||||
libs.endsWith('.js')
|
||||
) {
|
||||
output = libs;
|
||||
libs = [];
|
||||
}
|
||||
|
||||
this.extractions.push({ libs, output });
|
||||
}
|
||||
|
||||
@@ -24,32 +45,81 @@ class Extract {
|
||||
* @param {Entry} entry
|
||||
*/
|
||||
webpackEntry(entry) {
|
||||
this.extractions = this.extractions.map(
|
||||
entry.addExtraction.bind(entry)
|
||||
);
|
||||
this.entry = entry;
|
||||
|
||||
// If we are extracting vendor libraries, then we also need
|
||||
// to extract Webpack's manifest file to assist with caching.
|
||||
if (this.extractions.length) {
|
||||
this.extractions.push(
|
||||
path.join(entry.base, 'manifest').replace(/\\/g, '/')
|
||||
);
|
||||
}
|
||||
this.extractions.forEach(extraction => {
|
||||
extraction.output = this.extractionPath(extraction.output);
|
||||
|
||||
if (extraction.libs.length) {
|
||||
this.entry.addExtraction(extraction);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* webpack plugins to be appended to the master config.
|
||||
*/
|
||||
webpackPlugins() {
|
||||
// If we're extracting any vendor libraries, then we
|
||||
// need to add the CommonChunksPlugin to strip out
|
||||
// all relevant code into its own file.
|
||||
if (this.extractions.length) {
|
||||
return new webpack.optimize.CommonsChunkPlugin({
|
||||
names: this.extractions,
|
||||
minChunks: Infinity
|
||||
});
|
||||
webpackConfig(config) {
|
||||
const newConfig = webpackMerge.smart(config, this.config());
|
||||
|
||||
config.optimization = newConfig.optimization;
|
||||
}
|
||||
|
||||
config() {
|
||||
return {
|
||||
optimization: {
|
||||
// If we are extracting vendor libraries, then we also need
|
||||
// to extract Webpack's manifest file to assist with caching.
|
||||
runtimeChunk: {
|
||||
name: path
|
||||
.join(this.entry.base, 'manifest')
|
||||
.replace(/\\/g, '/')
|
||||
},
|
||||
|
||||
splitChunks: this.createSplitChunks()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
createSplitChunks() {
|
||||
let config = { cacheGroups: {} };
|
||||
|
||||
for (const [index, extraction] of this.extractions.entries()) {
|
||||
if (extraction.libs.length) {
|
||||
config.cacheGroups[`vendor${index}`] = this.createCacheGroup(
|
||||
extraction
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// If the user didn't specify any libraries to extract,
|
||||
// they likely want to extract all vendor libraries.
|
||||
if (Object.keys(config.cacheGroups).length === 0) {
|
||||
config.chunks = 'all';
|
||||
config.name = this.extractions[0].output;
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
createCacheGroup(extraction) {
|
||||
const libsPattern = extraction.libs.join('|');
|
||||
const pattern = new RegExp(`node_modules[\\\\/](${libsPattern})`, 'i');
|
||||
|
||||
return {
|
||||
test: pattern,
|
||||
name: extraction.output,
|
||||
chunks: 'all',
|
||||
enforce: true
|
||||
};
|
||||
}
|
||||
|
||||
extractionPath(outputPath) {
|
||||
if (outputPath) {
|
||||
return new File(outputPath)
|
||||
.pathFromPublic(Config.publicPath)
|
||||
.replace(/\.js$/, '')
|
||||
.replace(/\\/g, '/');
|
||||
}
|
||||
|
||||
return path.join(this.entry.base, 'vendor').replace(/\\/g, '/');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
let Preprocessor = require('./Preprocessor');
|
||||
let Assert = require('../Assert');
|
||||
|
||||
class FastSass extends Preprocessor {
|
||||
/**
|
||||
* The API name for the component.
|
||||
*/
|
||||
name() {
|
||||
return ['fastSass', 'standaloneSass'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the component.
|
||||
*
|
||||
* @param {*} src
|
||||
* @param {string} output
|
||||
* @param {Object} pluginOptions
|
||||
*/
|
||||
register(src, output, pluginOptions = {}) {
|
||||
Assert.exists(src);
|
||||
|
||||
return this.preprocess('fastSass', src, output, pluginOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* webpack plugins to be appended to the master config.
|
||||
*/
|
||||
webpackPlugins() {
|
||||
let FastSassPlugin = require('../webpackPlugins/FastSassPlugin');
|
||||
|
||||
return (super.webpackPlugins() || []).concat(
|
||||
new FastSassPlugin(this.details)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FastSass;
|
||||
+9
-4
@@ -1,12 +1,13 @@
|
||||
let glob = require('glob');
|
||||
let Assert = require('../Assert');
|
||||
let MockEntryPlugin = require('../webpackPlugins/MockEntryPlugin');
|
||||
let Vue = require('./Vue');
|
||||
|
||||
class JavaScript {
|
||||
constructor() {
|
||||
this.vue = new Vue();
|
||||
this.toCompile = [];
|
||||
|
||||
JavaScript.vueWebpackConfigApplied = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,7 +66,7 @@ class JavaScript {
|
||||
* webpack rules to be appended to the master config.
|
||||
*/
|
||||
webpackRules() {
|
||||
return [
|
||||
return [].concat([
|
||||
{
|
||||
test: /\.jsx?$/,
|
||||
exclude: /(node_modules|bower_components)/,
|
||||
@@ -76,7 +77,7 @@ class JavaScript {
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +86,11 @@ class JavaScript {
|
||||
* @param {Object} webpackConfig
|
||||
*/
|
||||
webpackConfig(webpackConfig) {
|
||||
this.vue.webpackConfig(webpackConfig);
|
||||
if (!JavaScript.vueWebpackConfigApplied) {
|
||||
this.vue.webpackConfig(webpackConfig);
|
||||
}
|
||||
|
||||
JavaScript.vueWebpackConfigApplied = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
-2
@@ -14,9 +14,16 @@ class Less extends Preprocessor {
|
||||
* @param {*} src
|
||||
* @param {string} output
|
||||
* @param {Object} pluginOptions
|
||||
* @param {Array} postCssPlugins
|
||||
*/
|
||||
register(src, output, pluginOptions = {}) {
|
||||
this.preprocess('less', src, output, pluginOptions);
|
||||
register(src, output, pluginOptions = {}, postCssPlugins = []) {
|
||||
return this.preprocess(
|
||||
'less',
|
||||
src,
|
||||
output,
|
||||
pluginOptions,
|
||||
postCssPlugins
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-1
@@ -11,7 +11,11 @@ class Notifications extends AutomaticComponent {
|
||||
return new WebpackNotifierPlugin({
|
||||
title: 'Laravel Mix',
|
||||
alwaysNotify: Config.notifications.onSuccess,
|
||||
hint: process.platform === 'linux' ? 'int:transient:1' : undefined,
|
||||
hint:
|
||||
process.platform === 'linux'
|
||||
? 'int:transient:1'
|
||||
: undefined,
|
||||
timeout: 2,
|
||||
contentImage: Mix.paths.root(
|
||||
'node_modules/laravel-mix/icons/laravel.png'
|
||||
)
|
||||
|
||||
+31
-21
@@ -9,8 +9,6 @@ class Preprocessor {
|
||||
*/
|
||||
webpackEntry(entry) {
|
||||
this.details.forEach(detail => {
|
||||
if (detail.type === 'fastsass') return;
|
||||
|
||||
entry.add(entry.keys()[0], detail.src.path());
|
||||
});
|
||||
}
|
||||
@@ -22,8 +20,6 @@ class Preprocessor {
|
||||
let rules = [];
|
||||
|
||||
this.details.forEach(preprocessor => {
|
||||
if (preprocessor.type === 'fastsass') return;
|
||||
|
||||
let outputPath = preprocessor.output.filePath
|
||||
.replace(Config.publicPath + path.sep, path.sep)
|
||||
.replace(/\\/g, '/');
|
||||
@@ -88,22 +84,18 @@ class Preprocessor {
|
||||
if (preprocessor.type !== 'postCss') {
|
||||
loaders.push({
|
||||
loader: `${preprocessor.type}-loader`,
|
||||
options: Object.assign(preprocessor.pluginOptions, {
|
||||
sourceMap:
|
||||
preprocessor.type === 'sass' &&
|
||||
Config.processCssUrls
|
||||
? true
|
||||
: Mix.isUsing('sourcemaps')
|
||||
})
|
||||
options: this.loaderOptions(preprocessor)
|
||||
});
|
||||
}
|
||||
|
||||
rules.push({
|
||||
test: preprocessor.src.path(),
|
||||
use: extractPlugin.extract({
|
||||
fallback: 'style-loader',
|
||||
use: loaders
|
||||
})
|
||||
use: Mix.isUsing('hmr')
|
||||
? ['style-loader', ...loaders]
|
||||
: extractPlugin.extract({
|
||||
fallback: 'style-loader',
|
||||
use: loaders
|
||||
})
|
||||
});
|
||||
|
||||
this.extractPlugins = (this.extractPlugins || []).concat(
|
||||
@@ -122,6 +114,26 @@ class Preprocessor {
|
||||
return this.extractPlugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the preprocessor plugin options.
|
||||
*
|
||||
* @param {Object} preprocessor
|
||||
*/
|
||||
loaderOptions(preprocessor) {
|
||||
tap(preprocessor.pluginOptions.implementation, implementation => {
|
||||
if (typeof implementation === 'function') {
|
||||
preprocessor.pluginOptions.implementation = implementation();
|
||||
}
|
||||
});
|
||||
|
||||
return Object.assign(preprocessor.pluginOptions, {
|
||||
sourceMap:
|
||||
preprocessor.type === 'sass' && Config.processCssUrls
|
||||
? true
|
||||
: Mix.isUsing('sourcemaps')
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a generic CSS preprocessor.
|
||||
*
|
||||
@@ -129,8 +141,9 @@ class Preprocessor {
|
||||
* @param {string} src
|
||||
* @param {string} output
|
||||
* @param {object} pluginOptions
|
||||
* @param {Array} postCssPlugins
|
||||
*/
|
||||
preprocess(type, src, output, pluginOptions = {}) {
|
||||
preprocess(type, src, output, pluginOptions = {}, postCssPlugins = []) {
|
||||
Assert.preprocessor(type, src, output);
|
||||
|
||||
src = new File(src);
|
||||
@@ -144,13 +157,10 @@ class Preprocessor {
|
||||
type: this.constructor.name.toLowerCase(),
|
||||
src,
|
||||
output,
|
||||
pluginOptions
|
||||
pluginOptions,
|
||||
postCssPlugins
|
||||
});
|
||||
|
||||
if (type === 'fastSass') {
|
||||
Mix.addAsset(output);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
+12
-7
@@ -34,16 +34,21 @@ class PurifyCss extends AutomaticComponent {
|
||||
* @param {Object} options
|
||||
*/
|
||||
build(options) {
|
||||
if (typeof options === 'object' && options.paths) {
|
||||
let paths = options.paths;
|
||||
if (typeof options === 'object') {
|
||||
if (options.paths) {
|
||||
let paths = options.paths;
|
||||
|
||||
paths.forEach(path => {
|
||||
if (!path.includes('*')) return;
|
||||
paths.forEach(path => {
|
||||
if (!path.includes('*')) return;
|
||||
|
||||
options.paths.splice(paths.indexOf(path), 1);
|
||||
options.paths.splice(paths.indexOf(path), 1);
|
||||
|
||||
options.paths = paths.concat(glob.sync(path));
|
||||
});
|
||||
options.paths = paths.concat(glob.sync(path));
|
||||
});
|
||||
}
|
||||
options.minimize = options.hasOwnProperty('minimize')
|
||||
? options.minimize
|
||||
: Mix.inProduction();
|
||||
}
|
||||
|
||||
return options;
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@ class React extends JavaScript {
|
||||
* Required dependencies for the component.
|
||||
*/
|
||||
dependencies() {
|
||||
return ['babel-preset-react'].concat(super.dependencies());
|
||||
return ['@babel/preset-react'];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -13,7 +13,7 @@ class React extends JavaScript {
|
||||
*/
|
||||
babelConfig() {
|
||||
return {
|
||||
presets: ['react']
|
||||
presets: ['@babel/preset-react']
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+25
-3
@@ -1,19 +1,40 @@
|
||||
let Preprocessor = require('./Preprocessor');
|
||||
|
||||
class Sass extends Preprocessor {
|
||||
/**
|
||||
* Required dependencies for the component.
|
||||
*/
|
||||
dependencies() {
|
||||
this.requiresReload = true;
|
||||
|
||||
return tap(
|
||||
[
|
||||
'sass-loader@7.*',
|
||||
Mix.seesNpmPackage('node-sass') ? 'node-sass' : 'sass'
|
||||
],
|
||||
dependencies => {
|
||||
if (Config.processCssUrls) {
|
||||
dependencies.push('resolve-url-loader@2.3.1');
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the component.
|
||||
*
|
||||
* @param {*} src
|
||||
* @param {string} output
|
||||
* @param {Object} pluginOptions
|
||||
* @param {Array} postCssPlugins
|
||||
*/
|
||||
register(src, output, pluginOptions = {}) {
|
||||
register(src, output, pluginOptions = {}, postCssPlugins = []) {
|
||||
return this.preprocess(
|
||||
'sass',
|
||||
src,
|
||||
output,
|
||||
this.pluginOptions(pluginOptions)
|
||||
this.pluginOptions(pluginOptions),
|
||||
postCssPlugins
|
||||
);
|
||||
}
|
||||
|
||||
@@ -27,7 +48,8 @@ class Sass extends Preprocessor {
|
||||
return Object.assign(
|
||||
{
|
||||
precision: 8,
|
||||
outputStyle: 'expanded'
|
||||
outputStyle: 'expanded',
|
||||
implementation: () => require('sass')
|
||||
},
|
||||
pluginOptions,
|
||||
{ sourceMap: true }
|
||||
|
||||
+9
-2
@@ -14,8 +14,9 @@ class Stylus extends Preprocessor {
|
||||
* @param {*} src
|
||||
* @param {string} output
|
||||
* @param {Object} pluginOptions
|
||||
* @param {Array} postCssPlugins
|
||||
*/
|
||||
register(src, output, pluginOptions = {}) {
|
||||
register(src, output, pluginOptions = {}, postCssPlugins = []) {
|
||||
pluginOptions = Object.assign(
|
||||
{
|
||||
preferPathResolver: 'webpack'
|
||||
@@ -23,7 +24,13 @@ class Stylus extends Preprocessor {
|
||||
pluginOptions
|
||||
);
|
||||
|
||||
return this.preprocess('stylus', src, output, pluginOptions);
|
||||
return this.preprocess(
|
||||
'stylus',
|
||||
src,
|
||||
output,
|
||||
pluginOptions,
|
||||
postCssPlugins
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -12,7 +12,7 @@ class TypeScript extends JavaScript {
|
||||
* Required dependencies for the component.
|
||||
*/
|
||||
dependencies() {
|
||||
return ['ts-loader', 'typescript'].concat(super.dependencies());
|
||||
return ['ts-loader', 'typescript'].concat();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,7 +35,7 @@ class TypeScript extends JavaScript {
|
||||
* @param {Object} config
|
||||
*/
|
||||
webpackConfig(config) {
|
||||
super.webpackConfig(config)
|
||||
super.webpackConfig(config);
|
||||
|
||||
config.resolve.extensions.push('.ts', '.tsx');
|
||||
config.resolve.alias['vue$'] = 'vue/dist/vue.esm.js';
|
||||
|
||||
+3
-10
@@ -32,16 +32,9 @@ class Version {
|
||||
* webpack plugins to be appended to the master config.
|
||||
*/
|
||||
webpackPlugins() {
|
||||
let WebpackChunkHashPlugin = require('webpack-chunk-hash');
|
||||
|
||||
return [
|
||||
new webpack[
|
||||
Mix.inProduction()
|
||||
? 'HashedModuleIdsPlugin'
|
||||
: 'NamedModulesPlugin'
|
||||
](),
|
||||
new WebpackChunkHashPlugin()
|
||||
];
|
||||
if (Mix.inProduction()) {
|
||||
return [new webpack.HashedModuleIdsPlugin()];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+126
-97
@@ -1,20 +1,19 @@
|
||||
let { VueLoaderPlugin } = require('vue-loader');
|
||||
let ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||
let { without } = require('lodash');
|
||||
|
||||
class Vue {
|
||||
/**
|
||||
* Create a new Vue instance.
|
||||
*/
|
||||
constructor() {
|
||||
this.requiresNewCssExtract = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Required dependencies for the component.
|
||||
*/
|
||||
dependencies() {
|
||||
let dependencies = ['vue-template-compiler'];
|
||||
|
||||
if (Config.extractVueStyles && Config.globalVueStyles) {
|
||||
return ['sass-resources-loader']; // Required for importing global styles into every component.
|
||||
dependencies.push('sass-resources-loader');
|
||||
}
|
||||
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -22,127 +21,157 @@ class Vue {
|
||||
*
|
||||
* @param {Object} webpackConfig
|
||||
*/
|
||||
webpackConfig(config) {
|
||||
let { vueLoaderOptions, extractPlugin } = this.vueLoaderOptions();
|
||||
|
||||
config.module.rules.push({
|
||||
webpackConfig(webpackConfig) {
|
||||
webpackConfig.module.rules.push({
|
||||
test: /\.vue$/,
|
||||
loader: 'vue-loader',
|
||||
exclude: /bower_components/,
|
||||
options: vueLoaderOptions
|
||||
loader: 'vue-loader'
|
||||
});
|
||||
|
||||
if (this.requiresNewCssExtract) {
|
||||
config.plugins.push(extractPlugin);
|
||||
}
|
||||
webpackConfig.plugins.push(new VueLoaderPlugin());
|
||||
|
||||
this.updateCssLoaders(webpackConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* vue-loader-specific options.
|
||||
* Update all preprocessor loaders to support CSS extraction.
|
||||
*
|
||||
* @param {Object} webpackConfig
|
||||
*/
|
||||
vueLoaderOptions() {
|
||||
let extractPlugin = this.extractPlugin();
|
||||
updateCssLoaders(webpackConfig) {
|
||||
// Basic CSS and PostCSS
|
||||
this.updateCssLoader('css', webpackConfig, rule => {
|
||||
rule.loaders.find(
|
||||
loader => loader.loader === 'postcss-loader'
|
||||
).options = this.postCssOptions();
|
||||
});
|
||||
|
||||
if (Config.extractVueStyles) {
|
||||
var sassLoader = extractPlugin.extract({
|
||||
use: 'css-loader!sass-loader?indentedSyntax',
|
||||
fallback: 'vue-style-loader'
|
||||
});
|
||||
// LESS
|
||||
this.updateCssLoader('less', webpackConfig);
|
||||
|
||||
var scssLoader = extractPlugin.extract({
|
||||
use: 'css-loader!sass-loader',
|
||||
fallback: 'vue-style-loader'
|
||||
});
|
||||
// SASS
|
||||
let sassCallback = rule => {
|
||||
if (Mix.seesNpmPackage('sass')) {
|
||||
rule.loaders.find(
|
||||
loader => loader.loader === 'sass-loader'
|
||||
).options.implementation = require('sass');
|
||||
}
|
||||
|
||||
if (Config.globalVueStyles) {
|
||||
scssLoader.push({
|
||||
loader: 'sass-resources-loader',
|
||||
options: {
|
||||
resources: Mix.paths.root(Config.globalVueStyles)
|
||||
}
|
||||
});
|
||||
|
||||
sassLoader.push({
|
||||
rule.loaders.push({
|
||||
loader: 'sass-resources-loader',
|
||||
options: {
|
||||
resources: Mix.paths.root(Config.globalVueStyles)
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let vueLoaderOptions = Object.assign(
|
||||
{
|
||||
loaders: Config.extractVueStyles
|
||||
? {
|
||||
js: {
|
||||
loader: 'babel-loader',
|
||||
options: Config.babel()
|
||||
},
|
||||
// SCSS
|
||||
this.updateCssLoader('scss', webpackConfig, sassCallback);
|
||||
|
||||
scss: scssLoader,
|
||||
// SASS
|
||||
this.updateCssLoader('sass', webpackConfig, sassCallback);
|
||||
|
||||
sass: sassLoader,
|
||||
|
||||
css: extractPlugin.extract({
|
||||
use: 'css-loader',
|
||||
fallback: 'vue-style-loader'
|
||||
}),
|
||||
|
||||
stylus: extractPlugin.extract({
|
||||
use:
|
||||
'css-loader!stylus-loader?paths[]=node_modules',
|
||||
fallback: 'vue-style-loader'
|
||||
}),
|
||||
|
||||
less: extractPlugin.extract({
|
||||
use: 'css-loader!less-loader',
|
||||
fallback: 'vue-style-loader'
|
||||
})
|
||||
}
|
||||
: {
|
||||
js: {
|
||||
loader: 'babel-loader',
|
||||
options: Config.babel()
|
||||
}
|
||||
},
|
||||
postcss: Config.postCss
|
||||
},
|
||||
Config.vue
|
||||
);
|
||||
|
||||
return { vueLoaderOptions, extractPlugin };
|
||||
// STYLUS
|
||||
this.updateCssLoader('styl', webpackConfig);
|
||||
}
|
||||
|
||||
extractPlugin() {
|
||||
if (typeof Config.extractVueStyles === 'string') {
|
||||
this.requiresNewCssExtract = true;
|
||||
/**
|
||||
* Update a single CSS loader.
|
||||
*
|
||||
* @param {string} loader
|
||||
* @param {Object} webpackConfig
|
||||
* @param {Function} callback
|
||||
*/
|
||||
updateCssLoader(loader, webpackConfig, callback) {
|
||||
let rule = webpackConfig.module.rules.find(rule => {
|
||||
return rule.test instanceof RegExp && rule.test.test('.' + loader);
|
||||
});
|
||||
|
||||
return new ExtractTextPlugin(this.extractFilePath());
|
||||
}
|
||||
callback && callback(rule);
|
||||
|
||||
let preprocessorName = Object.keys(Mix.components.all())
|
||||
.reverse()
|
||||
.find(componentName => {
|
||||
return ['sass', 'less', 'stylus', 'postCss'].includes(
|
||||
componentName
|
||||
);
|
||||
if (Config.extractVueStyles) {
|
||||
let extractPlugin = this.extractPlugin();
|
||||
|
||||
rule.loaders = extractPlugin.extract({
|
||||
fallback: 'style-loader',
|
||||
use: without(rule.loaders, 'style-loader')
|
||||
});
|
||||
|
||||
if (!preprocessorName) {
|
||||
this.requiresNewCssExtract = true;
|
||||
|
||||
return new ExtractTextPlugin(this.extractFilePath());
|
||||
this.addExtractPluginToConfig(extractPlugin, webpackConfig);
|
||||
}
|
||||
|
||||
return Mix.components.get(preprocessorName).extractPlugins.slice(-1)[0];
|
||||
}
|
||||
|
||||
extractFilePath() {
|
||||
/**
|
||||
* Fetch the appropriate postcss plugins for the compile.
|
||||
*/
|
||||
postCssOptions() {
|
||||
if (Mix.components.get('postCss')) {
|
||||
return {
|
||||
plugins: Mix.components.get('postCss').details[0].postCssPlugins
|
||||
};
|
||||
}
|
||||
|
||||
// If the user has a postcss.config.js file in their project root,
|
||||
// postcss-loader will automatically read and fetch the plugins.
|
||||
if (File.exists(Mix.paths.root('postcss.config.js'))) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return { plugins: Config.postCss };
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an extract text plugin to the webpack config plugins array.
|
||||
*
|
||||
* @param {Object} extractPlugin
|
||||
* @param {Object} webpackConfig
|
||||
*/
|
||||
addExtractPluginToConfig(extractPlugin, webpackConfig) {
|
||||
if (extractPlugin.isNew) {
|
||||
webpackConfig.plugins.push(extractPlugin);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the appropriate extract plugin.
|
||||
*/
|
||||
extractPlugin() {
|
||||
// If the user set extractVueStyles: true, we'll try
|
||||
// to append the Vue styles to an existing CSS chunk.
|
||||
if (typeof Config.extractVueStyles === 'boolean') {
|
||||
let preprocessorName = Object.keys(Mix.components.all())
|
||||
.reverse()
|
||||
.find(componentName => {
|
||||
return ['sass', 'less', 'stylus', 'postCss'].includes(
|
||||
componentName
|
||||
);
|
||||
});
|
||||
|
||||
if (preprocessorName) {
|
||||
return Mix.components
|
||||
.get(preprocessorName)
|
||||
.extractPlugins.slice(-1)[0];
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, we'll need to whip up a fresh extract text instance.
|
||||
return tap(
|
||||
new ExtractTextPlugin(this.extractFileName()),
|
||||
extractPlugin => {
|
||||
extractPlugin.isNew = true;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the extract file name.
|
||||
*/
|
||||
extractFileName() {
|
||||
let fileName =
|
||||
typeof Config.extractVueStyles === 'string'
|
||||
? Config.extractVueStyles
|
||||
: 'vue-styles.css';
|
||||
: '/css/vue-styles.css';
|
||||
|
||||
return fileName.replace(Config.publicPath, '').replace(/^\//, '');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user