目录结构
admin/->后端网络包js/.yarnrcwebpack.config.js包.json资产/->叶状网络包管理员/文件内容:
.yarnrc
--modules-folder node_modules_admin这正确地创建了 admin/node_modules_adminAdmin 使用 boostrap 3,Front 使用 boostrap 4 所以需要单独的文件夹.
webpack.config.js
var Encore = require('@symfony/webpack-encore');再来一次//将存储编译资产的项目目录.setOutputPath('./../public/admin/')//Web 服务器用来访问上一个目录的公共路径.setPublicPath('/admin').cleanupOutputBeforeBuild().enableSourceMaps(!Encore.isProduction()).enableVersioning(Encore.isProduction()).createSharedEntry('供应商', ['jquery','引导',//'全日历','./js/vendor.js',//您也可以提取 CSS - 这将创建一个vendor.css"文件//这个 CSS 将不再*包含在 page1.css 或 page2.css 中//'bootstrap-sass/assets/stylesheets/_bootstrap.scss']).addEntry('js/admin', './js/admin.js').addEntry('js/datatables', './js/datatables.js').addStyleEntry('css/appLess', './css/app.less').addStyleEntry('css/admin', './css/admin.scss')//取消注释以定义项目的资产//.addEntry('js/app', './assets/js/app.js')//.addStyleEntry('css/app', './assets/css/app.scss')//如果您使用 Sass/SCSS 文件,则取消注释.enableSassLoader()//取消对需要 $/jQuery 作为全局变量的遗留应用程序的注释.autoProvidejQuery().autoProvideVariables({$: "jquery",jQuery: "jquery",'window.jQuery': 'jquery',波普尔:['popper.js','默认'],})//.enableVersioning().enableLessLoader()//.addLoader(//{test: require.resolve('signature_pad'), loader: 'expose?SignaturePad'},//).enableBuildNotifications()//.addLoader(//{//测试:require.resolve('wow.js/dist/wow.js'),//loader: 'exports?this.WOW'//}).addLoader({测试:/\.(jpe?g|png|gif)$/i,加载器:文件加载器",询问:{name:'[name].[ext]',输出路径:'图像/'//图片将被发送到public/assets/images/文件夹//图像将被放入DOM ;标记为例如.背景: url(assets/images/image.png);}});让 config = Encore.getWebpackConfig();config.resolve.alias = {'把手':'把手/dist/handlebars.min.js'};//模块.exports = {// 入口: [//'全日历',//...//]//}module.exports = config;package.json
{开发依赖":{"@symfony/webpack-encore": "^0.21.0","css-loader": "^1.0.0","文件加载器": "^1.1.11","少": "^3.0.4","less-loader": "^4.1.0","node-sass": "^4.9.3","sass-loader": "^7.1.0","url-loader": "^1.0.1","webpack-notifier": "^1.6.0"},依赖关系":{"admin-lte": "^2.4.8","bootstrap-editable": "^1.0.1","datatables-all": "^1.10.13","数据表按钮": "^1.0.3","datatables-fixedheader": "^3.1.0","datatables": "^1.10.19","datatables-bs": "^1.10.19","datatables-buttons-bs": "^1.5.1","datatables-dt": "^1.10.19","datatables-fixedheader-bs": "^3.1.3","eonasdan-bootstrap-datetimepicker": "^3.1.3","fullcalendar": "^2.9.1","车把": "^4.0.12","jquery": "^2.2.4","jquery-form": "^4.2.2","jquery-slimscroll": "^1.3.8","jquery-ui-bootstrap": "^1.0.0","jquery-validation": "^1.18.0","jquery.fancytree": "^2.30.0","js-cookie": "^2.2.0","砖石布局": "^4.2.2","popover": "^2.4.1","readmore-js": "^2.2.1","脚本加载器": "^0.7.2","select2": "^4.0.6-rc.1","timeago": "^1.6.3","timeago.js": "^4.0.0-beta.1","webpack-icons-installer": "^2.0.0","webpack-jquery-ui": "^2.0.1",x 可编辑":^1.5.1"},"license": "未授权",私人":真的,脚本":{"dev-server": "encore dev-server","dev": "encore dev","watch": "encore dev --watch","build": "encore 生产"}}config/framework.yaml
框架:秘密:'%env(APP_SECRET)%'#default_locale: zh#csrf_protection: 真#http_method_override: 真# 启用会话支持.请注意,会话仅在您读取或写入时才会启动.# 删除或注释此部分以明确禁用会话支持.会议:handler_id:~资产:包:后端:json_manifest_path: '%kernel.project_dir%/public/admin/manifest.json'前端:json_manifest_path: '%kernel.project_dir%/public/build/manifest.json'我去管理目录
~/PhpstormProjects/vista_bralion_docker/admin$ yarn install纱线安装 v1.12.1[1/4] 解析包...成功 已经是最新的.在 0.94 秒内完成.尝试生成文件
~/PhpstormProjects/vista_bralion_docker/admin$ yarn run encore dev --watch纱线运行 v1.12.1错误命令encore"未找到.info 访问 yarnpkg/en/docs/cli/run 获取有关此命令的文档.我尝试直接运行 encore
:~/PhpstormProjects/vista_bralion_docker/admin$ node_modules_admin/@symfony/webpack-encore/bin/encore.js内部/模块/cjs/loader.js:550抛出错误;^错误:找不到模块@babel/core"在 Function.Module._resolveFilename (internal/modules/cjs/loader.js:548:15)在 Function.Module._load (internal/modules/cjs/loader.js:475:25)在 Module.require (internal/modules/cjs/loader.js:598:17)在要求 (internal/modules/cjs/helpers.js:11:18)在对象(/home/grek/PhpstormProjects/vista_bralion_docker/admin/node_modules_admin/@symfony/webpack-encore/lib/config/parse-runtime.js:15:15)在 Module._compile (internal/modules/cjs/loader.js:654:30)在 Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)在 Module.load (internal/modules/cjs/loader.js:566:32)在 tryModuleLoad (internal/modules/cjs/loader.js:506:12)在 Function.Module._load (internal/modules/cjs/loader.js:498:3)这里是 admin/yarn.lock
然后一切正常
其他可能的解决方案是:
- 删除 node_modules 目录和 yarn.lock 文件(如果有)
- 之后:yarn run --ignore-engines
我在带有数字海洋的云道上使用它
参考资料
directory structure
admin/ -> backend webpack js/ .yarnrc webpack.config.js package.json assets/ -> frond webpackadmin/ files content :
.yarnrc
--modules-folder node_modules_adminThis correctly create admin/node_modules_admin Admin use boostrap 3, Front use boostrap 4 so need separate folders.
webpack.config.js
var Encore = require('@symfony/webpack-encore'); Encore // the project directory where compiled assets will be stored .setOutputPath('./../public/admin/') // the public path used by the web server to access the previous directory .setPublicPath('/admin') .cleanupOutputBeforeBuild() .enableSourceMaps(!Encore.isProduction()) .enableVersioning(Encore.isProduction()) .createSharedEntry('vendor', [ 'jquery', 'bootstrap', // 'fullcalendar', './js/vendor.js', // you can also extract CSS - this will create a 'vendor.css' file // this CSS will *not* be included in page1.css or page2.css anymore // 'bootstrap-sass/assets/stylesheets/_bootstrap.scss' ]) .addEntry('js/admin', './js/admin.js') .addEntry('js/datatables', './js/datatables.js') .addStyleEntry('css/appLess', './css/app.less') .addStyleEntry('css/admin', './css/admin.scss') // uncomment to define the assets of the project // .addEntry('js/app', './assets/js/app.js') // .addStyleEntry('css/app', './assets/css/app.scss') // uncomment if you use Sass/SCSS files .enableSassLoader() // uncomment for legacy applications that require $/jQuery as a global variable .autoProvidejQuery() .autoProvideVariables({ $: "jquery", jQuery: "jquery", 'window.jQuery': 'jquery', Popper: ['popper.js', 'default'], }) // .enableVersioning() .enableLessLoader() // .addLoader( // {test: require.resolve('signature_pad'), loader: 'expose?SignaturePad'}, // ) .enableBuildNotifications() // .addLoader( // { // test: require.resolve('wow.js/dist/wow.js'), // loader: 'exports?this.WOW' // }) .addLoader( { test: /\.(jpe?g|png|gif)$/i, loader:"file-loader", query:{ name:'[name].[ext]', outputPath:'images/' //the images will be emmited to public/assets/images/ folder //the images will be put in the DOM <style> tag as eg. background: url(assets/images/image.png); } }) ; let config = Encore.getWebpackConfig(); config.resolve.alias = { 'handlebars': 'handlebars/dist/handlebars.min.js' }; // module.exports = { // entry: [ // 'fullcalendar', // ... // ] // } module.exports = config;package.json
{ "devDependencies": { "@symfony/webpack-encore": "^0.21.0", "css-loader": "^1.0.0", "file-loader": "^1.1.11", "less": "^3.0.4", "less-loader": "^4.1.0", "node-sass": "^4.9.3", "sass-loader": "^7.1.0", "url-loader": "^1.0.1", "webpack-notifier": "^1.6.0" }, "dependencies": { "admin-lte": "^2.4.8", "bootstrap-editable": "^1.0.1", "datatables-all": "^1.10.13", "datatables-buttons": "^1.0.3", "datatables-fixedheader": "^3.1.0", "datatables": "^1.10.19", "datatables-bs": "^1.10.19", "datatables-buttons-bs": "^1.5.1", "datatables-dt": "^1.10.19", "datatables-fixedheader-bs": "^3.1.3", "eonasdan-bootstrap-datetimepicker": "^3.1.3", "fullcalendar": "^2.9.1", "handlebars": "^4.0.12", "jquery": "^2.2.4", "jquery-form": "^4.2.2", "jquery-slimscroll": "^1.3.8", "jquery-ui-bootstrap": "^1.0.0", "jquery-validation": "^1.18.0", "jquery.fancytree": "^2.30.0", "js-cookie": "^2.2.0", "masonry-layout": "^4.2.2", "popover": "^2.4.1", "readmore-js": "^2.2.1", "script-loader": "^0.7.2", "select2": "^4.0.6-rc.1", "timeago": "^1.6.3", "timeago.js": "^4.0.0-beta.1", "webpack-icons-installer": "^2.0.0", "webpack-jquery-ui": "^2.0.1", "x-editable": "^1.5.1" }, "license": "UNLICENSED", "private": true, "scripts": { "dev-server": "encore dev-server", "dev": "encore dev", "watch": "encore dev --watch", "build": "encore production" } }config/framework.yaml
framework: secret: '%env(APP_SECRET)%' #default_locale: en #csrf_protection: true #http_method_override: true # Enables session support. Note that the session will ONLY be started if you read or write from it. # Remove or comment this section to explicitly disable session support. session: handler_id: ~ assets: packages: backend: json_manifest_path: '%kernel.project_dir%/public/admin/manifest.json' frontend: json_manifest_path: '%kernel.project_dir%/public/build/manifest.json'I go to admin directory
~/PhpstormProjects/vista_bralion_docker/admin$ yarn install yarn install v1.12.1 [1/4] Resolving packages... success Already up-to-date. Done in 0.94s.try generate files
~/PhpstormProjects/vista_bralion_docker/admin$ yarn run encore dev --watch yarn run v1.12.1 error Command "encore" not found. info Visit yarnpkg/en/docs/cli/run for documentation about this command.I try direct run encore
:~/PhpstormProjects/vista_bralion_docker/admin$ node_modules_admin/@symfony/webpack-encore/bin/encore.js internal/modules/cjs/loader.js:550 throw err; ^ Error: Cannot find module '@babel/core' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:548:15) at Function.Module._load (internal/modules/cjs/loader.js:475:25) at Module.require (internal/modules/cjs/loader.js:598:17) at require (internal/modules/cjs/helpers.js:11:18) at Object.<anonymous> (/home/grek/PhpstormProjects/vista_bralion_docker/admin/node_modules_admin/@symfony/webpack-encore/lib/config/parse-runtime.js:15:15) at Module._compile (internal/modules/cjs/loader.js:654:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10) at Module.load (internal/modules/cjs/loader.js:566:32) at tryModuleLoad (internal/modules/cjs/loader.js:506:12) at Function.Module._load (internal/modules/cjs/loader.js:498:3)here is admin/yarn.lock
pastebin/cpYSxbRz
解决方案The solution for me was to execute this command:
$ yarn add --dev vue vue-loader@15.x vue-template-compilerThis is the result:
then everything works fine
Other solution possible is this:
- Remove the node_modules directory and the yarn.lock file if you have one
- After: yarn run --ignore-engines
I use this on cloudways with digital ocean
Referencia
更多推荐
错误命令“encore"未找到.(单独的后端 webpack)
发布评论