I am a beginner of the Angularjs 1.0 and my script was not working so I used gulp
to compile ec6 to ec5 using the code below. I was able to build it and made main.js
. How do I connect it when I launch an application? npm related commands
not working.
I am using MVC5 for the back end so I just launch it then I can see the project going.
How do I use main.js
to launch application or debugging application?
'use strict';
const gulp = require('gulp');
const browserSync = require('browser-sync').create();
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const livereload = require('gulp-livereload');
const concat = require('gulp-concat');
gulp.task('scripts', function () {
return gulp.src('./Scripts/**/*.js')
.pipe(concat('main.js'))
.pipe(gulp.dest('build/js'));
});
// Compile Sass & Inject Into Browser
gulp.task('sass', function () {
return gulp.src(['./Content/scss/*.scss'])
.pipe(sass())
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(gulp.dest("./Content"))
.pipe(livereload());
});
// Watch Sass & Serve
gulp.task('serve', ['sass'], function () {
gulp.watch(['./Content/scss/*.scss'], ['sass']);
});
// Default Task
gulp.task('default', ['serve', 'scripts','sass']);
I did that in Django framework as below: index.html
{% if load_minified_scripts %}
<script src="{% static "minified_assets/js/site.min.js" %}"></script>
{% else %}
<script src="{% static "script/app.js" %}"></script>
<script src="{% static "script/controller.js" %}"></script>
{% endif %}
This load_minified_scripts
is set from server side.
views.py
@csrf_protect
@requires_csrf_token
def index(request):
if request.session.session_key is None:
request.session['has_session'] = True
request.session.modified = True
return render(request, 'index.html', {'user': request.user,
'debug': settings.DEBUG,
'session_key': request.session.session_key,
"load_minified_scripts": settings.LOAD_MINIFIED_SCRIPTS}
, content_type="text/html")
Depending on env
, the settings.LOAD_MINIFIED_SCRIPTS
was getting its value. For DEV
env , it was false
.
Similarly you can do it for other language as well.