javascript - 如何在 grunt-cli 中提供外部端口,以便在服务器上托管它?
问题描述
我正在使用 docker 制作图像来运行我的前端。
它在我的笔记本电脑上运行良好,但在我的服务器上,我无法通过浏览器访问它。
您可以查看我的屏幕截图以了解我的浏览器对此有何评论。
所以,我的项目在 Angular (grunt-cli) 前端,后端在烧瓶中,数据库是 mongodb。后端工作正常,但 grunt-cli,我无法通过浏览器访问它,但我可以 curl http://:9000 来查看内容。
这是我的 Gruntfile.js——
module.exports = function(grunt) {
// ===========================================================================
// CONFIGURE GRUNT ===========================================================
// ===========================================================================
grunt.initConfig({
// get the configuration info from package.json ----------------------------
// this way we can use things like name and version (pkg.name)
pkg: grunt.file.readJSON('package.json'),
// configure jshint to validate js files -----------------------------------
jshint: {
options: {
reporter: require('jshint-stylish')
},
all: ['Grunfile.js', 'src/components/**/*.js']
},
// configure uglify to minify js files -------------------------------------
uglify: {
options: {
banner: '/*\n <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> \n*/\n'
},
build: {
files: {
'dist/js/components.min.js': 'src/components/**/*.js'
}
}
},
// compile less stylesheets to css -----------------------------------------
less: {
build: {
files: {
'dist/css/pretty.css': 'src/css/pretty.less'
}
}
},
// configure cssmin to minify css files ------------------------------------
cssmin: {
options: {
banner: '/*\n <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> \n*/\n'
},
build: {
files: {
'dist/css/style.min.css': 'src/css/style.css'
}
}
},
// configure watch to auto update ------------------------------------------
watch: {
stylesheets: {
files: ['src/**/*.css', 'src/**/*.less'],
tasks: ['less', 'cssmin']
},
scripts: {
files: 'src/**/*.js',
tasks: ['jshint', 'uglify']
}
},
express:{
all:{
options:{
port:9000,
hostname:'0.0.0.0',
bases:['./src'],
livereload: true
}
}
}
});
// ===========================================================================
// LOAD GRUNT PLUGINS ========================================================
// ===========================================================================
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-express');
// ===========================================================================
// CREATE TASKS ==============================================================
// ===========================================================================
grunt.registerTask('serve-waalos', ['jshint','cssmin','uglify','express','watch']);
grunt.registerTask('default', ['test', 'build']);
};
解决方案
推荐阅读
- ansible - 你如何编写一个 ansible 回调插件来仅显示来自我通过调试明确写出的消息?
- r - 对数似然集成未观察到的异质性返回错误的系数
- python - 在 Keras 中加入两个 DirectoryIterator
- karate - 禁用 HTML 空手道测试报告
- php - 如何从 SDK/框架向父应用发送推送通知?
- java - Spring Boot 创建新项目时 pom.xml 出错
- apache-spark - 在 Kubernetes 上运行 Spark 时工作人员出错
- google-bigquery - BigQuery 时间戳采用什么格式?
- list - Display data from SQFlite into Grid List (Flutter)?
- java - C++和Java中引用赋值的区别