mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2024-11-10 19:57:09 +03:00
Make requested changes:
* Reorder meta tasks to the bottom * Fix JS compilation issue * Replace strings concatenation with templates
This commit is contained in:
parent
17a9632031
commit
b6b7176d02
|
@ -25,25 +25,25 @@ const uglify = require('gulp-uglify-es').default
|
||||||
|
|
||||||
// Relative paths function
|
// Relative paths function
|
||||||
function pathsConfig(appName) {
|
function pathsConfig(appName) {
|
||||||
this.app = "./" + (appName || pjson.name)
|
this.app = `./${pjson.name}`
|
||||||
var vendorsRoot = 'node_modules/'
|
const vendorsRoot = 'node_modules'
|
||||||
|
|
||||||
return {
|
return {
|
||||||
{% if cookiecutter.custom_bootstrap_compilation == 'y' %}
|
{% if cookiecutter.custom_bootstrap_compilation == 'y' %}
|
||||||
bootstrapSass: vendorsRoot + '/bootstrap/scss',
|
bootstrapSass: `${vendorsRoot}/bootstrap/scss`,
|
||||||
vendorsJs: [
|
vendorsJs: [
|
||||||
vendorsRoot + 'jquery/dist/jquery.slim.js',
|
`${vendorsRoot}/jquery/dist/jquery.slim.js`,
|
||||||
vendorsRoot + 'popper.js/dist/umd/popper.js',
|
`${vendorsRoot}/popper.js/dist/umd/popper.js`,
|
||||||
vendorsRoot + 'bootstrap/dist/js/bootstrap.js'
|
`${vendorsRoot}/bootstrap/dist/js/bootstrap.js`,
|
||||||
],
|
],
|
||||||
{% endif %}
|
{% endif %}
|
||||||
app: this.app,
|
app: this.app,
|
||||||
templates: this.app + '/templates',
|
templates: `${this.app}/templates`,
|
||||||
css: this.app + '/static/css',
|
css: `${this.app}/static/css`,
|
||||||
sass: this.app + '/static/sass',
|
sass: `${this.app}/static/sass`,
|
||||||
fonts: this.app + '/static/fonts',
|
fonts: `${this.app}/static/fonts`,
|
||||||
images: this.app + '/static/images',
|
images: `${this.app}/static/images`,
|
||||||
js: this.app + '/static/js'
|
js: `${this.app}/static/js`,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ function styles() {
|
||||||
cssnano({ preset: 'default' }) // minify result
|
cssnano({ preset: 'default' }) // minify result
|
||||||
]
|
]
|
||||||
|
|
||||||
return src(paths.sass + '/project.scss')
|
return src(`${paths.sass}/project.scss`)
|
||||||
.pipe(sass({
|
.pipe(sass({
|
||||||
includePaths: [
|
includePaths: [
|
||||||
{% if cookiecutter.custom_bootstrap_compilation == 'y' %}
|
{% if cookiecutter.custom_bootstrap_compilation == 'y' %}
|
||||||
|
@ -83,7 +83,7 @@ function styles() {
|
||||||
|
|
||||||
// Javascript minification
|
// Javascript minification
|
||||||
function scripts() {
|
function scripts() {
|
||||||
return src(paths.js + '/project.js')
|
return src(`${paths.js}/project.js`)
|
||||||
.pipe(plumber()) // Checks for errors
|
.pipe(plumber()) // Checks for errors
|
||||||
.pipe(uglify()) // Minifies the js
|
.pipe(uglify()) // Minifies the js
|
||||||
.pipe(rename({ suffix: '.min' }))
|
.pipe(rename({ suffix: '.min' }))
|
||||||
|
@ -105,19 +105,11 @@ function vendorScripts() {
|
||||||
|
|
||||||
// Image compression
|
// Image compression
|
||||||
function imgCompression() {
|
function imgCompression() {
|
||||||
return src(paths.images + '/*')
|
return src(`${paths.images}/*`)
|
||||||
.pipe(imagemin()) // Compresses PNG, JPEG, GIF and SVG images
|
.pipe(imagemin()) // Compresses PNG, JPEG, GIF and SVG images
|
||||||
.pipe(dest(paths.images))
|
.pipe(dest(paths.images))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate all assets
|
|
||||||
const generateAssets = parallel(
|
|
||||||
styles,
|
|
||||||
scripts,
|
|
||||||
{% if cookiecutter.custom_bootstrap_compilation == 'y' %}vendorScripts,{% endif %}
|
|
||||||
imgCompression
|
|
||||||
)
|
|
||||||
|
|
||||||
// Run django server
|
// Run django server
|
||||||
function runServer(cb) {
|
function runServer(cb) {
|
||||||
var cmd = spawn('python', ['manage.py', 'runserver'], {stdio: 'inherit'})
|
var cmd = spawn('python', ['manage.py', 'runserver'], {stdio: 'inherit'})
|
||||||
|
@ -130,19 +122,31 @@ function runServer(cb) {
|
||||||
// Browser sync server for live reload
|
// Browser sync server for live reload
|
||||||
function initBrowserSync() {
|
function initBrowserSync() {
|
||||||
browserSync.init(
|
browserSync.init(
|
||||||
[paths.css + "/*.css", paths.js + "*.js", paths.templates + '*.html'], {
|
[
|
||||||
proxy: "localhost:8000"
|
`${paths.css}/*.css`,
|
||||||
})
|
`${paths.js}/*.js`,
|
||||||
|
`${paths.templates}/*.html`
|
||||||
|
], {
|
||||||
|
proxy: "localhost:8000"
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Watch
|
// Watch
|
||||||
function watchPaths() {
|
function watchPaths() {
|
||||||
watch(paths.sass + '/*.scss', styles)
|
watch(`${paths.sass}/*.scss`, styles)
|
||||||
watch(paths.js + '/*.js', scripts).on("change", reload)
|
watch(`${paths.templates}/**/*.html`).on("change", reload)
|
||||||
watch(paths.images + '/*', imgCompression)
|
watch([`${paths.js}/*.js`, `!${paths.js}/*.min.js`], scripts).on("change", reload)
|
||||||
watch(paths.templates + '/**/*.html').on("change", reload)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate all assets
|
||||||
|
const generateAssets = parallel(
|
||||||
|
styles,
|
||||||
|
scripts,
|
||||||
|
{% if cookiecutter.custom_bootstrap_compilation == 'y' %}vendorScripts,{% endif %}
|
||||||
|
imgCompression
|
||||||
|
)
|
||||||
|
|
||||||
// Set up dev environment
|
// Set up dev environment
|
||||||
const dev = parallel(
|
const dev = parallel(
|
||||||
runServer,
|
runServer,
|
||||||
|
@ -151,3 +155,5 @@ const dev = parallel(
|
||||||
)
|
)
|
||||||
|
|
||||||
exports.default = series(generateAssets, dev)
|
exports.default = series(generateAssets, dev)
|
||||||
|
exports["generate-assets"] = generateAssets
|
||||||
|
exports["dev"] = dev
|
||||||
|
|
Loading…
Reference in New Issue
Block a user