vue file dont working in atom IDE with webpack - vue.js

I'm creating a project in Rails with vue, for this I'm working with webpack, what happens and my text editor, atom IDE, does not process the .vue files, I've tried the steps that the documentation recommends, but I do not know what I'm doing wrong
I provided loading the vue-loader by npm, but I still can not see the .vue files in my project, then I did it by configuring in the webpack.config.js file, and nothing. Then I leave the links of the things I did that did not work.
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import OptimizeCssAssetsPlugin from '../../../src/';
module.exports = {
entry: './index',
module: {
rules: [
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: { loader: 'style-loader' },
use: {
loader: 'css-loader',
options: { minimize: true }
}
},
vue: {
loaders: {
sass: 'style!css!sass?indentedSyntax',
scss: 'style!css!sass'
}
},
plugins: [
new ExtractTextPlugin('file.css'),
new OptimizeCssAssetsPlugin({
assetNameRegExp: /optimize-me\.css/g
})
};
I hope to be able to work the .vue files

Related

SassError: Can't find stylesheet to import. (not from node_modules) (using mochapack)

Attempting to load SCSS files from the relative path within Vue component fails.
Config details:
Using "mochapack": "^2.1.2",
Using "sass-loader": "^10.2.0",
Using
$ node -v
v14.17.0
webpack.config-test.js:
const nodeExternals = require('webpack-node-externals');
const { VueLoaderPlugin } = require('vue-loader');
const { alias } = require('./webpack.config.js'); // webpack.config.js is our main, this config is for testing.
module.exports = {
target: 'node', // webpack should compile node compatible code
externals: [nodeExternals()], // in order to ignore all modules in node_modules folder
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader'
},
{
test: /\.js$/,
loader: 'babel-loader'
},
{
test: /\.css$/,
use: [
'vue-style-loader',
'css-loader'
]
},
{
test: /\.s[ac]ss$/i,
use: [
{
loader: 'vue-style-loader',
options: {
sourceMap: true,
sourceMapContents: false
}
},
{
loader: 'css-loader',
options: {
sourceMap: true,
sourceMapContents: false
}
},
'resolve-url-loader',
'sass-loader',
]
}
]
},
resolve: {
alias: {
...alias
},
extensions: ['.js', '.vue']
},
plugins: [
new VueLoaderPlugin(),
]
};
As you can see, attempting to use URL rewriting per webpack recommendation still fails.
Error:
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Can't find stylesheet to import.
╷
126 │ #forward "../settings.scss";
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
╵
Debugging attempts:
Checked settings.scss for errors, even when the file is empty it still can't find it.
It def has something to do with the relative path, but the plugin that is supposed to resolve that doesn't seem to work. I'm hoping this is just me not using it right. But I followed their instructions.
I had a similar error, turned out there was a space in the name of a parent directory of the project that was causing the settings.scss to not be found. Try removing the whitespace from all parent directories.

How to add vue-awesome icons in nuxt app?

I'm wanted to add font-awesome in my universal NuxtJs app. so i used the vue-awesome package for that.
Now after istalling the package i got this error:
Unexpected identifier
After reading from nuxt repo on github (nuxt repo 1, nuxt repo 2), i realised that the issue comes when rendering it on the server. SSR.
So for dev sake i silenced it with :
in nuxt.config.js
plugins: [{ src: '~plugins/vue-awesome', ssr: false },]
After developing, i had to face it, and i got stuck at this error :
"Unexpected token <"
here is the code :
~/plugins/vue-awesome
import Vue from 'vue';
import Icon from 'vue-awesome/components/Icon.vue';
import './icons.js';
Vue.component('icon', Icon);
~/plugins/icons.js
import 'vue-awesome/icons/sign-in-alt'
import 'vue-awesome/icons/shopping-basket'
...
nuxt.config.js
module.exports = {
build: {
extend(config, ctx) {
if (ctx.isClient) {
config.module.rules.push({
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: /(node_modules)/
})
} else {
config.externals = [ nodeExternals({
whitelist: ['vue-awesome']
})]
}
}
},
plugins: ['~plugins/vue-awesome.js']
}
Finanlly fixed it
nuxt.config.js
plugins: [
'~plugins/vue-awesome',
],
build: {
transpile: [/vue-awesome/]
},

Loading .mp3 files with Nuxt.js

I'm facing a problem with loading .mp3 files with Nuxt.JS (Vue.js)...
I've tried to load the file without an specific loader and webpack tells that he need one specific loader for the file and when i added the url-loader in nuxt.config.js file:
build: {
/*
** Run ESLint on save
*/
extend (config, { isDev, isClient }) {
if (isDev && isClient) {
config.module.rules.push({
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: /(node_modules)/
})
config.module.rules.push({
test: /\.(ogg|mp3|wav)$/i,
loader: 'url-loader'
})
}
}
throws the error:
TypeError
Cannot read property 'middleware' of undefined
Somebody have used another loaders in Nuxt.Js?
Thanks in advance!
From Nuxt.js official documentation: https://nuxtjs.org/faq/webpack-audio-files/
export default {
build: {
extend (config, ctx) {
config.module.rules.push({
test: /\.(ogg|mp3|wav|mpe?g)$/i,
loader: 'file-loader',
options: {
name: '[path][name].[ext]'
}
})
}
}
}
Normally, you just have to use the file-loader in your webpack config :
{
test: /\.mp3$/,
include: '/path/to/directory',
loader: 'file-loader'
}
Can you share your config file ?
Instead of import directly in javascript, I recommend you to load your file with a generic resource loader.

MiniCssExtractPlugin fail to load css file inside node modules

I use MiniCssExtractPlugin in a project which has some problem when I import css file inside node modules in a vue file. Import statement:
import '../../../node_modules/video.js/dist/video-js.css
Webpack config:
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: { url: false }
}
]
}
No style has been applied using the above setting. I tried to create a test.css file and put around in different folder. All directory will work except inside node_modules folder. Please help.
Extra info:
If I replace MiniCssExtractPlugin with style-loader, everything will be ok.
{
test: /\.css$/,
use: [
{ loader: 'style-loader' },
{
loader: 'css-loader',
options: { url: false }
}
]
}

...mapState SyntaxError in Vue.js, with vuex

when I'm using ...mapState in vue.js, I ran into an error when bundling files with webpack. The error is
Module build failed: SyntaxError: Unexpected token.
I've tried kinds of babel plugins such as stage-0 and transform-object-rest-spread.
Howerver, none seems to be ok for me. Would you please so kind tell me how to solve it?
the source code is
<script type="text/babel">
import { mapState } from 'vuex';
let [a, b, ...other] = [1,2,3,5,7,9]; // this line is ok
console.log(a);
console.log(b);
console.log(other);
export default{
computed:{
localComputed(){
return 10;
},
...mapState({ //this line caused the error
count: state => state.count
})
},
methods: {
increment() {
this.$store.commit('increment');
},
decrement() {
this.$store.commit('decrement');
}
}
}
</script>
and this is the webpack config fragment
{
test: /\.(js|es|es6|jsx)$/,
use: [
{
loader: 'babel-loader',
options: {
presets: [
['react'],
['es2015', {modules: false, loose: true}],
['stage-2']
],
plugins: [
['transform-runtime'],
// https://github.com/JeffreyWay/laravel-mix/issues/76
['transform-object-rest-spread'],
['transform-es2015-destructuring']
],
comments: false,
cacheDirectory: true
}
},
{
loader: 'eslint-loader',
options: {
configFile: eslintConfigPath
}
}
],
exclude: excludeReg
}
I had a similar problem a while ago. As far as I can see, your issue is that your babel-loader does not currently work on .vue files (which is correct as such).
The vue-loader, which handles .vue files, uses babel internally as well, but it won't use webpack's babel-loader config. The easiest way to provide a config for babel in the vue-loader is (unfortunately) creating a separate .babelrc file with your babel config in the root folder of your project:
.babelrc
{
presets: [
["react"],
["es2015", { "modules": false, "loose": true}],
["stage-2"]
],
plugins: [
["transform-runtime"],
["transform-object-rest-spread"],
["transform-es2015-destructuring"]
]
}
Note that .babelrc requires valid JSON.