结果我误解了webpack的工作原理。
我以为Webpack会继续在后台运行并为我编译资产。
为了解释我为什么这么想,让我从头开始:
我从GitHub派生了一个rails项目(
https://github.com/DMPRoadmap/roadmap
),启动并运行它,但我意识到当我通过浏览器访问rails应用程序网站时,它不会显示图像,而且它的布局也不会应用(样式表)。我意识到我需要使用webpack来编译这些资产。
所以我开始运行webpack
npm install
和
npm run bundle
,终端显示如下:
$ npm run bundle
> roadmap@1.0.0 bundle /Users/my-name/dev/testing/dmp-roadmap/lib/assets
> webpack
Webpack is watching the filesâ¦
Hash: 1af8780dadb3d5abe275
Version: webpack 3.11.0
Time: 7360ms
Asset Size Chunks Chunk Names
images/bournemouth_logo.png 16.1 kB [emitted]
fonts/glyphicons-halflings-regular.eot 20.1 kB [emitted]
fonts/glyphicons-halflings-regular.woff 23.4 kB [emitted]
fonts/glyphicons-halflings-regular.ttf 45.4 kB [emitted]
fonts/glyphicons-halflings-regular.svg 109 kB [emitted]
fonts/fontawesome-webfont.eot 166 kB [emitted]
fonts/fontawesome-webfont.woff2 77.2 kB [emitted]
fonts/fontawesome-webfont.woff 98 kB [emitted]
fonts/fontawesome-webfont.ttf 166 kB [emitted]
fonts/fontawesome-webfont.svg 444 kB [emitted] [big]
./stylesheets/skins/lightgray/content.inline.min.css 3.17 kB [emitted]
./stylesheets/skins/lightgray/content.min.css 3.57 kB [emitted]
./stylesheets/skins/lightgray/fonts/tinymce-small.eot 9.49 kB [emitted]
./stylesheets/skins/lightgray/fonts/tinymce-small.svg 24.7 kB [emitted]
./stylesheets/skins/lightgray/fonts/tinymce-small.ttf 9.3 kB [emitted]
./stylesheets/skins/lightgray/fonts/tinymce-small.woff 9.38 kB [emitted]
./stylesheets/skins/lightgray/fonts/tinymce.eot 17.6 kB [emitted]
./stylesheets/skins/lightgray/fonts/tinymce.svg 46 kB [emitted]
./stylesheets/skins/lightgray/fonts/tinymce.ttf 17.4 kB [emitted]
./stylesheets/skins/lightgray/fonts/tinymce.woff 17.5 kB [emitted]
./stylesheets/skins/lightgray/img/anchor.gif 53 bytes [emitted]
./stylesheets/skins/lightgray/img/loader.gif 2.61 kB [emitted]
./stylesheets/skins/lightgray/img/object.gif 152 bytes [emitted]
./stylesheets/skins/lightgray/img/trans.gif 43 bytes [emitted]
./stylesheets/skins/lightgray/skin.min.css 40 kB [emitted]
javascripts/application.js 3.26 MB 0 [emitted] [big] application
javascripts/vendor.js 317 kB 1 [emitted] [big] vendor
stylesheets/application.css 201 kB 0 [emitted] application
images/2013_Jisc_Logo_RGB72.png 2.12 kB [emitted]
images/asc.gif 54 bytes [emitted]
images/background.jpg 1.69 kB [emitted]
images/bg.gif 64 bytes [emitted]
images/dcc_logo_white.png 3.03 kB [emitted]
images/dcc_logo.png 907 bytes [emitted]
fonts/glyphicons-halflings-regular.woff2 18 kB [emitted]
images/desc.gif 54 bytes [emitted]
images/download.png 2.55 kB [emitted]
images/fullscreen.png 341 bytes [emitted]
images/favicon.ico 1.15 kB [emitted]
images/glyphicons-halflings-white.png 8.78 kB [emitted]
images/help_button.png 557 bytes [emitted]
images/glyphicons-halflings.png 12.8 kB [emitted]
images/logo.png 15.5 kB [emitted]
images/minus_laranja.png 408 bytes [emitted]
images/lancaster_logo.png 26.2 kB [emitted]
images/lse-library_logo.png 18.2 kB [emitted]
images/plus_laranja.png 781 bytes [emitted]
images/question-mark.png 2.57 kB [emitted]
images/rails.png 6.65 kB [emitted]
images/newcastle_logo.png 142 kB [emitted]
images/remove.png 681 bytes [emitted]
images/roadmap_logo_orange_grey.png 3.81 kB [emitted]
images/roadmap_logo_orange_white.png 3.56 kB [emitted]
images/salford_logo.png 8.36 kB [emitted]
images/select2-spinner.gif 1.85 kB [emitted]
images/select2.png 613 bytes [emitted]
images/select2x2.png 845 bytes [emitted]
images/uc3_logo_white.png 3.11 kB [emitted]
images/screencast.jpg 103 kB [emitted]
images/uc3_logo.jpg 4 kB [emitted]
images/ue_logo.png 26.9 kB [emitted]
videos/index.files/html5video/fullscreen.png 341 bytes [emitted]
videos/index.files/html5video/flashfox.swf 4.9 kB [emitted]
videos/index.files/html5video/html5ext.js 3.51 kB [emitted]
videos/index.files/html5video/screencast.jpg 103 kB [emitted]
videos/index.files/html5video/screencast.mp4 12.3 MB [emitted] [big]
videos/index.files/html5video/screencast.webm 13.7 MB [emitted] [big]
videos/index.files/html5video/screencast.m4v 13.8 MB [emitted] [big]
videos/index.files/html5video/screencast.ogv 24.7 MB [emitted] [big]
[15] ./javascripts/utils/links.js 4.71 kB {0} [built]
[18] ./javascripts/utils/paginable.js 1.09 kB {0} [built]
[27] ./javascripts/views/org_admin/questions/sharedEventHandlers.js 1.3 kB {0} [built]
[28] ./javascripts/views/org_admin/question_options/index.js 1.52 kB {0} [built]
[156] multi jquery timeago.js jquery-accessible-autocomplete-list-aria/jquery-accessible-autocomplete-list-aria jquery-ujs 64 bytes {1} [built]
[159] multi ./javascripts/application.js ./stylesheets/application.scss 40 bytes {0} [built]
[160] ./javascripts/application.js 1.77 kB {0} [built]
[236] ./javascripts/views/shared/sign_in_form.js 1.81 kB {0} [built]
[238] ./javascripts/views/super_admin/themes/new_edit.js 424 bytes {0} [built]
[239] ./javascripts/views/super_admin/users/edit.js 485 bytes {0} [built]
[240] ./javascripts/views/usage/index.js 7.67 kB {0} [built]
[289] ./javascripts/views/users/notification_preferences.js 622 bytes {0} [built]
[290] ./javascripts/views/users/admin_grant_permissions.js 4.43 kB {0} [built]
[291] ./javascripts/views/super_admin/notifications/edit.js 509 bytes {0} [built]
[292] ./stylesheets/application.scss 41 bytes {0} [built]
+ 291 hidden modules
Child extract-text-webpack-plugin node_modules/extract-text-webpack-plugin/dist node_modules/css-loader/index.js!node_modules/sass-loader/lib/loader.js!stylesheets/application.scss:
10 assets
[1] ./node_modules/css-loader!./node_modules/sass-loader/lib/loader.js!./stylesheets/application.scss 214 kB {0} [built]
+ 13 hidden modules
从跑步开始
npm运行包
不显示终端新行提示(我说的是
$
我认为它就像一个服务器,不断地为我的rails应用程序提供资产文件。
我刷新网站,它显示的形象和布局优美。
我通过按CTRL+C停止网页包并重新加载网站,它仍然显示图像和布局漂亮,我错误地得出结论,网页包现在是在后台提供文件。
但我错了。
在我按CTRL+C停止webpack进程后,webpack停止提供文件。但由于它已经编译了资产文件并将它们存储在我的项目目录中的公共目录中,所以我的网站只使用其中的文件。这就是为什么网站仍然显示图像和布局漂亮的实际原因。
所以,停止
npm运行包
和打电话一样
webpack
在我的例子中,我确实可以简单地按CTRL+C。
为了
npm run bundle -- -p
,我不知道它现在在做什么,在运行它之后(假设我已经运行了npm run bundle并使用CTRL+C停止它),网站将停止正确显示图像和布局。
另外,当我打电话给
ps aux | grep webpack
是因为
grep
是我看到的过程,每次我开始
格雷普
,这将是一个新的不同的过程,因此它将有不同的PID。按CTRL+C时,网页包进程已停止。