简体   繁体   English

在Laravel 5中的app.js中合并js文件

[英]combining js files in app.js in laravel 5

hi there I want create an app.js on laravel 5.4 您好,我想在laravel 5.4上创建一个app.js

webpack.mix.js webpack.mix.js

mix.js('resources/assets/js/app.js', 'public/js');

and in package.josn 并在package.josn中

{
  "private": true,
  "scripts": {
    "dev": "npm run development",
    "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch-poll": "npm run watch -- --watch-poll",
    "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
    "prod": "npm run production",
    "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
  },
  "devDependencies": {
    "axios": "^0.16.2",
    "bootstrap-sass": "^3.3.7",
    "jquery": "^3.1.1",
    "laravel-mix": "^1.0",
    "lodash": "^4.17.4",
    "vue": "^2.1.10"
  },
  "dependencies": {
    "laravel-echo": "^1.3.2",
    "pusher-js": "^4.1.0",
    "sweetalert": "^1.1.3",
    "webpack": "^3.5.5"
  }
}

I only needs this (to save in app.js) 我只需要这个(保存在app.js中)

    "laravel-echo": "^1.3.2",
    "pusher-js": "^4.1.0",
    "sweetalert": "^1.1.3",

how can I do it? 我该怎么做?

I try NMP run dev but it combine all js. 我尝试NMP run dev但它结合了所有js。

also what is 'webpack'? 还有什么是“ webpack”? do I need it? 我需要吗?

First make sure you have latest nodejs installed and then run npm install after installation is done. 首先,请确保您已安装最新的nodejs,然后在安装完成后运行npm install

On your webpack.mix.js add another line with your file that you want to create: 在webpack.mix.js上,在要创建的文件中添加另一行:

mix.js('resources/assets/js/yourfile.js', 'public/js');

place the code in that .js file then open terminal and run npm run dev this will compile the file to project public directory public/assets/js/yourfile.js after this run npm run watch this way any change that you make on your js file will be compiled automatically so you don't have to call npm run dev each time that you make a change. 将代码放在该.js文件中,然后打开终端并run npm run dev这将在run npm run dev将文件编译为项目公共目录public/assets/js/yourfile.jsnpm run watch这种方式npm run watch您对js所做的任何更改文件将自动编译,因此您每次进行更改时都不必调用npm run dev

webpack

Is a pre-configured webpack.config.js file to get you up and running as quickly as possible. 是预先配置的webpack.config.js文件,可让您尽快启动并运行。 Occasionally, you may need to manually modify this file(in our case we are referencing another js on webpack ). 有时,您可能需要手动修改此文件(在我们的情况下,我们正在引用webpack上的另一个js)。 You might have a special loader or plug-in that needs to be referenced 您可能有需要引用的特殊加载器或插件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM