arshtepe / css-file-loader Goto Github PK
View Code? Open in Web Editor NEWClone resources from link in css like images, fonts ...
License: MIT License
Clone resources from link in css like images, fonts ...
License: MIT License
I tried loading images and fonts using file-loader
without any success. do i decided to give this package a chance..
This is my webpack.conf.js file:
const path = require('path');
const webpack = require('webpack');
const UrlLoader = require('url-loader');
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
publicFolder = path.resolve(__dirname, 'public');
// appFolder = path.resolve(__dirname, 'app');
console.log(publicFolder);
module.exports = {
entry: {
// Selects main js file
main: './public/es6/index.js'
},
output: {
// Main path for the js folder
path: path.resolve(__dirname, 'public/js/'),
// Select teh name the main js file (after compression)
filename: 'bundle.js',
// Public path
// publicPath: 'http://localhost:8080',
publicPath: '/public/js/',
// publicPath: path.resolve(__dirname, 'public/js/'),
// Name the chunkFile (in case of external scripts)
chunkFilename: '[name].[contenthash].js'
},
module: {
rules: [ // Vue Files
{
test: /\.vue$/,
exclude: /node_modules/,
loader: 'vue-loader',
options: {
loader: {
scss: 'vue-style-loader!css-loader!sass-loader',
css: 'vue-style-loader!css-loader'
}
}
},
// JS files
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
// CSS / SASS files
{
// test: /\.scss$/,
test: /\.(sa|sc|c)ss$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
},
{
loader: 'css-loader',
options: {
url: false,
minimize: true,
sourceMap: true
}
},
{
loader: 'postcss-loader'
},
{
loader: 'css-file-loader',
options: {
publicPath: '/public/fonts/'
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
minimize: true
}
}
]
},
// Font|SVG: Make Webpack know how and from where to load the files.
{
test: /\.(png|gif|jpe|jpg|woff|woff2|eot|ttf|svg)(\?.*$|$)/,
use: [
{
loader: 'file-loader',
options: {
name: './public/fonts/[hash].[ext]',
// emitFile: false,
// useRelativePath: false,
outputPath: './public/fonts/',
publicPath: './public/fonts/'
}
}
]
}
/*{
test: /\.(png|gif|jpe|jpg|woff|woff2|eot|ttf|svg)(\?.*$|$)/,
use: [{
loader: 'url-loader',
options: {
fallback: 'file-loader',
// useRelativePath: true,
// outputPath: publicFolder + '/fonts/',
// include: './node_modules/',
name: '[path][hash].[ext]',
limit: 100000
}
}]
}*/
]
},
plugins: [
// Load jQuery globally
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery'
}),
// Hot module
// new webpack.HotModuleReplacementPlugin(),
// BrowserSync: Load page automatically on change
new BrowserSyncPlugin({
proxy: 'https://potato.mywebsite.com/',
port: 3000,
files: [
'**/*.php'
],
ghostMode: {
clicks: false,
location: false,
forms: false,
scroll: false
},
minify: false,
injectChanges: true,
logFileChanges: true,
logLevel: 'debug',
logPrefix: 'webpack',
notify: true,
reloadDelay: 0
}),
// Provides a way to customize how progress is reported during a compilation
new webpack.ProgressPlugin(),
// Loads Vue
new VueLoaderPlugin(),
// For webpack-dev-server (currently not in use)
// new webpack.HotModuleReplacementPlugin(),
// Handle css in different files (scss file in login.js for example to a hashed login.css file)
new MiniCssExtractPlugin({ filename: '../css/[name].css' }),
// CSS assets during the Webpack build and will optimize \ minimize the CSS
new OptimizeCSSAssetsPlugin({}),
// Not sure if needed yet
new webpack.NamedModulesPlugin()
],
devServer: {
// https: true,
headers: { 'Access-Controll-Allow-Origin': '*' },
compress: true,
quiet: true,
hot: true,
inline: true
}
};
Returns this error on npm run dev
:
Child mini-css-extract-plugin node_modules/css-loader/index.js??ref--2-1!node_modules/postcss-loader/src/index.js!node_modules/css-file-loader/src/index.js??ref--2-3!node_modules/sass-loader/lib/loader.js??ref--2-4!public/scss/style.scss:
Entrypoint mini-css-extract-plugin = *
[./node_modules/css-loader/index.js?!./node_modules/postcss-loader/src/index.js!./node_modules/css-file-loader/src/index.js?!./node_modules/sass-loader/lib/loader.js?!./public/scss/style.scss] ./node_modules/css-loader??ref--2-1!./node_modules/postcss-loader/src!./node_modules/css-file-loader/src??ref--2-3!./node_modules/sass-loader/lib/loader.js??ref--2-4!./public/scss/style.scss 500 bytes {mini-css-extract-plugin} [built] [failed] [1 error]ERROR in ./public/scss/style.scss (./node_modules/css-loader??ref--2-1!./node_modules/postcss-loader/src!./node_modules/css-file-loader/src??ref--2-3!./node_modules/sass-loader/lib/loader.js??ref--2-4!./public/scss/style.scss) Module build failed (from ./node_modules/css-file-loader/src/index.js): TypeError: Cannot read property 'match' of undefined at rule.declarations.forEach.declaration (/www/node_modules/css-file-loader/src/index.js:26:52) at Array.forEach (<anonymous>) at ast.stylesheet.rules.forEach.rule (/www/node_modules/css-file-loader/src/index.js:25:31) at Array.forEach (<anonymous>) at Object.module.exports (/www/node_modules/css-file-loader/src/index.js:23:26)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.