Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

html中资源引用url携带构建目录dist #1

Closed
xiangtao123 opened this issue Dec 19, 2016 · 2 comments
Closed

html中资源引用url携带构建目录dist #1

xiangtao123 opened this issue Dec 19, 2016 · 2 comments

Comments

@xiangtao123
Copy link

xiangtao123 commented Dec 19, 2016

https://npm.proxy.ustclug.org/package/gulp-concat-replace

gulpfile.js:

var dist_path='dist';
gulp.task('concat-replace',['minify-css','concat-js'], function(){
return gulp.src(dist_path+'/*.html')
.pipe(concatreplace({
prefix:'concat',
base:'../',
output:{
css:dist_path+'/css',
js:dist_path+'/js'
}
}))
.pipe(gulp.dest(dist_path));// html 替换后的目录
});

index.html :

<link rel="stylesheet" href="dist/css/index_concat_1.css">

资源引用地址,携带着dist目录。
和您例子中的不一致

@xiangtao123
Copy link
Author

xiangtao123 commented Dec 19, 2016

将output设置为:css/jss,html中引用地址为:css/a.css, js/b.css
然后,将文件(index_concat_2.js/index_concat_1.css)移动到dist对应目录下

concatreplace({
prefix:'concat',
base:'../',
output:{
css:'css',
js:'js'
}
});

gulp.src('js/') .pipe(gulp.dest(dist_path+'/js/'));
gulp.src('css/
').pipe(gulp.dest(dist_path+'/css/'));
del('js/');
del('css/
');

通过此方式,可以正常使用

@xiangtao123
Copy link
Author

最后使用 gulp-html-replace 插件更直接。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant