首页 > 解决方案 > Rails 5.1 将 js 文件从 app/assets/javascripts 移动到 app/javascripts

问题描述

我试图将我的 JS 文件app/assets/javascriptsapp/javascript. 基本上从 Asset Pipeline 转移到 Webpack。

我在这个过程中遇到了多个错误。

1.我唯一做的就是移动文件并从中删除预编译语句config/initializers/assets.rb

这就是我得到的:

DEPRECATION WARNING: The asset "disallow-char.js" is not present in the asset pipeline.Falling back to an asset that may be in the public folder.
This behavior is deprecated and will be removed.
To bypass the asset pipeline and preserve this behavior,
use the `skip_pipeline: true` option.

2.然后我在文件上添加了以下内容html.haml

```= javascript_include_tag 'disallow-char.js', skip_pipeline: true```

这就是我得到的:

Started GET "/javascripts/disallow-char.js" for ::1 at 2018-04-26 15:11:18 -0500
Processing by ErrorsController#routing as JS
  Parameters: {"any_bad_route"=>"javascripts/disallow-char"}
::1 - - [26/Apr/2018:15:11:18 CDT] "GET /packs/application-26fc747cc9104717d89e.js HTTP/1.1" 304 0

在浏览器上,我收到此错误:

GET http://localhost:3000/javascripts/disallow-char.js net::ERR_ABORTED

该文件的位置是app/javascripts/frontend/disallow-char.js

我的app/javascript/packs/application.js样子如下:

/* eslint no-console:0 */
// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.
//
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
// layout file, like app/views/layouts/application.html.erb
const frontend = require.context('../frontend', true, /\.js$/);
application.load(definitionsFromContext(frontend));

export default application;

有没有人见过那里的错误?有什么我想念的吗?

标签: asset-pipelineruby-on-rails-5.1webpacker

解决方案


推荐阅读