How to get npm module working locally on Laravel/Vue Project? - laravel

I know the question is broad but at this point I'm not necessarily sure how to specify it. I am currently working on a Laravel/Vue project, and I want to create an extracted module that will eventually be an NPM package. The reason I want to extract it is because I will use this chunk of code as a mixin within various Vue components.
I want to do this all locally so that I don't have to continuously mess with NPM, so I set up the link between my project and my module via the npm link command. I can confirm in my Project that there is a symbolic link directory in the node_modules directory, pointing to my Module.
In my Project, I have the code from the mixin executing a function inside another method of my Vue component, like so:
this.updateState(response.state);
I am importing and defining the mixin in that file like so:
import UpdatesState from 'module';
export default {
mixins: [UpdatesState],
This updateState method is defined in my Module. Inside my Module, here is what my module/src/mixins/UpdateState file looks like:
export default {
methods: {
updateState(state) {
this.$store.commit('state', state);
}
},
}
Also in the Module, I have an index.js file that looks like this:
import UpdatesState from './mixins/UpdatesState'
export default {
UpdatesState
}
My Module's package.json looks like this:
{
"name": "module",
"description": "Supporting modules",
"main": "src/index.js",
"author": "Hoolakoola",
"license": "MIT"
}
When I was running this code from within the actual source of the Project and just referencing it by its absolute path, it was working fine. But now that I am trying to extract it, it is not working properly. I am not getting any errors when compiling the Project, and there are no errors in the console. Any idea what is going wrong here and how I can fix it? Thank you.

Related

Copy (Clipboard Module) missing for ag-grid-vue

I noticed that ag-grid-vue and #ag-grid-enterprise/all-modules does not include the Clipboard module. Copy, copy with headers, and paste are all missing in the context menu.
/* Package.json */
"dependencies": {
"#ag-grid-enterprise/all-modules": "^22.1.2",
"#ag-grid-enterprise/clipboard": "^22.1.0",
"ag-grid-community": "^22.1.1",
"ag-grid-vue": "^22.1.1"
context menu
you can try installing
"#ag-grid-enterprise/clipboard": "^22.1.1" in the package.json.
then add this in the app.component.ts file
import {ModuleRegistry} from 'ag-grid-community';
import {ClipboardModule} from '#ag-grid-enterprise/clipboard';
ModuleRegistry.register(ClipboardModule as any);
this worked for me. Let me know
You are currently mixing the two approaches of including AG Grid in your project.
You only need the following in your package.json file as these packages contain all the code you need following the AG Grid 'package' approach. The package ag-grid-enterprise contains the Clipboard functionality without the need to register modules.
/* Package.json */
"dependencies": {
"ag-grid-enterprise": "^22.1.2",
"ag-grid-community": "^22.1.1",
"ag-grid-vue": "^22.1.1"
From the docs
It is important that you do not mix packages and modules in the same
application as this will result in AG Grid being included twice and
doubling your bundle size! All modules are scoped by either
#ag-grid-community/* or #ag-grid-enterprise/* and should not be mixed
with the standalone packages of ag-grid-community and
ag-grid-enterprise.
Modules
Packages
#ag-grid-community/xxxxx
ag-grid-community
#ag-grid-enterprise/xxxxx
ag-grid-enterprise
I have written about this more in this blog post.

Laravel Webpack mix.js Cannot Compile with extenstion .vue

I'm new to webpack in Laravel. I already managed to compile the default scripts into one. However, when I tried to add a new Vue Controller in a separate folder, it seems it will not be included during npm run dev.
Currently I have this set-up
-assets
--js
---app.js
---test.vue
mix.js([
'resources/assets/js/app.js',
'resources/assets/js/test.vue'
], 'public/js/app.js');
This will work. However when I put test.vue inside a folder.
-assets
--js
---app.js
--controllers
--test.vue
mix.js([
'resources/assets/js/app.js',
'resources/assets/js/controllers/test.vue'
], 'public/js/app.js');
However, when I changed it from test.vue to test.js it will compile. Does the file extension matter? when compiling mix.js?
Can someone help me out on this? Thanks!
If i am not mistaken you can't compile single .vue files using webpack without some sort of loader
Using Vue.component() and importing a vue file into a .js file and then compiling the .js will work.
This might be of help: https://github.com/vuejs/vue-loader
Vue Single-File Component (SFC) Spec
A *.vue file is a custom file format that uses HTML-like syntax to
describe a Vue component. Each *.vue file consists of three types of
top-level language blocks: , , and , and
optionally additional custom blocks:
vue-loader will parse the file, extract each language block, pipe them
through other loaders if necessary, and finally assemble them back
into an ES Module whose default export is a Vue.js component options
object.

How do I get Aurelia to process scss

I have created a new Aurelia using the cli and setting scss for the CSS Processor and webpack for the bundler. My problem is the scss seems to be ignored and I cant work out why.
I have a file in project /src/styles/styles.scss
Inside the aurelia.json file (I have added the source property)
...
"cssProcessor": {
"id": "sass",
"displayName": "Sass",
"fileExtension": ".scss",
"source": "src/**/*.scss"
},
...
Have you imported your scss-file in any components? I think you can make it work by adding this line to your app.ts file (or whatever startup component you are using)
import 'app.scss';
Requiring it in the template should also work, a discussion of both methods is available here: https://github.com/aurelia/webpack-plugin/issues/14

How to set custom folder path for sub folders in vendor when installing a package?

I want to install a package into my local project.For that I'm creating a composer.json file in my project folder is given below, it gives the total vendor folder of that package into my custom folder in my project. Its working fine.....
{
"config": {
"vendor-dir": "/var/www/html/Test2/Testing/Down"
},
}
It gives the package into 'Down' folder.
But, now I want the sub folders or files in that packages to be installed in my custom folders like js/css folders in my project.
For example i want jquery.js file into my local folder path
/var/www/html/Test2/Testing/assests/js
From the package "frameworks/jquery".
For that, what changes are needed in my composer.json file?
Composer is used to bring in packages to support the PHP code of a project, here is how they describe it on the Composer website:
Composer is a tool for dependency management in PHP. It allows you to
declare the libraries your project depends on and it will manage
(install/update) them for you.
In other words, if you need to do logging in your PHP code and decide to use the publicly available monolog package, you use composer to bring that package into your project, then in your PHP code, you can call monolog functions.
Using config to rename the vendor directory is trying to use Composer in a way that doesn't fit the intent of the tool. The vendor directory is used to hold the packages brought in (such as the monolog code). The vendor-dir value is simply renaming that directory.
Since you have GitHub listed as a tag, you could possibly use cloning to get your files to your website directory.
I've modified my composer.json file, it looks like the below:
{
"config": {
"vendor-dir": "/var/www/html/Test2/Testing/Down"
},
"require": {
},
"scripts": {
"post-package-install": [
"php -r \"exec('cp -r /var/www/html/Test2/Testing/Down/frameworks/jquery/* /var/www/html/Test2/Testing/assets/js');\""
]
}
}
It will gives all selected files in a package to my local folder.
Briefly the files in the folder 'frameworks/jquery' are copied into my local 'assets/js' folder.

gulp, wiredep and custom sass file

So I made a library that I can bower install using a direct link. I can use this library from another internal application by adding the library name in the dependency of the bower.json file. When other internal application does a bower update, the changes I made on the library will be applied to their application. This part is working very well.
Now, I'd like the other software devs to have freedom to change the styles. They can create css file directly and that will work. However, it's a hackish route. I can provide them the same settings file that I use.
So i tried putting that file in the main section of the bower.json but wiredep is processing it. I put it in exclude and the error is gone when I run gulp.
"main": [
"dist/stylesheet.css",
"src/_settings.scss"
],
this is the code that prevented it from being parsed by wiredep
wiredep: {
directory: 'bower_components',
exclude: ['css/foundation.css','src/_settings.scss']
}
Am I right that I'll have to create a new gulp task and put 'src/_settings.scss' as gulp.src like this
gulp.task('sasstask2', function () {
return gulp.src('src/_settings.scss')
.pipe($.sass())
.pipe(gulp.dest('src/css'));
});
I also like the generate css to be injected to index.html but not sure how to do it? Will wiredep automatically inject it to index.html?

Resources