소개
webpack2 기반의 다중 항목 프로젝트 스캐폴딩으로, 주로 extract-text-webpack-plugin을 사용하여 js 및 css 공개 코드 추출을 구현하고, html-webpack-plugin을 사용하여 html 다중 항목을 구현하고, less-loader를 사용하여 더 적은 양을 구현합니다. 컴파일 및 postcss-loader 브라우저 호환 접두사를 자동으로 추가하도록 autoprefixer를 구성하고, 이미지 버전 번호와 템플릿을 HTML에 추가하려면 html-withimg-loader를, ES6 트랜스코딩을 구현하려면 babel-loader를, 빌드 속도를 높이기 위해 happypack 멀티스레딩을 구성하세요.
Directory
├── dist # 构建后的目录 ├── config # 项目配置文件 │ ├── webpack.config.js # webpack 配置文件 │ └── postcss.config.js # postcss 配置文件 ├── src # 程序源文件 │ └── js # 入口 │ ├ └── index.js # 匹配 view/index.html │ ├ └── user │ ├ ├ ├── index.js # 匹配 view/user/index.html │ ├ ├ ├── list.js # 匹配 view/user/list.html │ ├ └── lib # JS 库等,不参与路由匹配 │ ├ ├── jquery.js │ └── view │ ├ └── index.html # 对应 js/index.js │ ├ └── user │ ├ ├── index.html # 对应 js/user/index.js │ ├ ├── list.html # 对应 js/user/list.js │ └── css # css 文件目录 │ ├ └── base.css │ ├ └── iconfont.css │ └── font # iconfont 文件目录 │ ├ └── iconfont.ttf │ ├ └── iconfont.css │ └── img # 图片文件目录 │ ├ └── pic1.jpg │ ├ └── pic2.png │ └── template # html 模板目录 │ └── head.html │ └── foot.html
Configuration
다중 항목
JS
디렉토리에 따라 다중 항목 배열 가져오기JS
目录获取多入口数组
const ROOT = process.cwd(); // 根目录 let entryJs = getEntry('./src/js/**/*.js'); /** * 根据目录获取入口 * @param {[type]} globPath [description] * @return {[type]} [description] */ function getEntry (globPath) { let entries = {}; Glob.sync(globPath).forEach(function (entry) { let basename = path.basename(entry, path.extname(entry)), pathname = path.dirname(entry); // js/lib/*.js 不作为入口 if (!entry.match(/\/js\/lib\//)) { entries[pathname.split('/').splice(3).join('/') + '/' + basename] = pathname + '/' + basename; } }); return entries; } // webpack 配置 const config = { entry: entryJs, output: { filename: 'js/[name].js?[chunkhash:8]', chunkFilename: 'js/[name].js?[chunkhash:8]', path: path.resolve(ROOT, 'dist'), publicPath: '/' }, }
module
使用 babel 实现 ES2015 转 ES5,less 转 css 并使用 postcss 实现 autoprefixer 自动添加浏览器兼容,url-loader 实现 css 引用图片、字体添加版本号,html-withimg-loader 实现 html 引用图片添加版本号并实现模板功能。
module: { rules: [ { test: /\.js$/, exclude: /(node_modules|bower_components)/, use: { loader: 'babel-loader?id=js', options: { presets: ['env'] } } }, { test: /\.(less|css)$/, use: ExtractTextPlugin.extract({ fallback: 'style-loader?id=styles', use: [{ loader: 'css-loader?id=styles', options: { minimize: !IsDev } }, { loader: 'less-loader?id=styles' }, { loader: 'postcss-loader?id=styles', options: { config: { path: PostcssConfigPath } } } ] }) }, { test: /\.(png|jpg|gif)$/, use: [ { loader: 'url-loader', options: { limit: 100, publicPath: '', name: '/img/[name].[ext]?[hash:8]' } } ] }, { test: /\.(eot|svg|ttf|woff)$/, use: [ { loader: 'url-loader', options: { limit: 100, publicPath: '', name: '/font/[name].[ext]?[hash:8]' } } ] }, // @see { test: /\.(htm|html)$/i, loader: 'html-withimg-loader?min=false' } ] }, // postcss.config.js module.exports = { plugins: [ require('autoprefixer')({ browsers: ['> 1%', 'last 5 versions', 'not ie <h3 id="View-视图">View 视图</h3><blockquote><p>根据目录对应关系,获取 js 对应的 html 入口</p></blockquote><pre class="brush:php;toolbar:false">let entryHtml = getEntryHtml('./src/view/**/*.html'), configPlugins; entryHtml.forEach(function (v) { configPlugins.push(new HtmlWebpackPlugin(v)); }); // webpack 配置 resolve: { alias: { views: path.resolve(ROOT, './src/view') } }, /** * 根据目录获取 Html 入口 * @param {[type]} globPath [description] * @return {[type]} [description] */ function getEntryHtml (globPath) { let entries = []; Glob.sync(globPath).forEach(function (entry) { let basename = path.basename(entry, path.extname(entry)), pathname = path.dirname(entry), // @see minifyConfig = IsDev ? '' : { removeComments: true, collapseWhitespace: true, minifyCSS: true, minifyJS: true }; entries.push({ filename: entry.split('/').splice(2).join('/'), template: entry, chunks: ['common', pathname.split('/').splice(3).join('/') + '/' + basename], minify: minifyConfig }); }); return entries; }
plugins
使用 happypack 多线程加快构建速度,CommonsChunkPlugin 实现提取公用 js 为单独文件,extract-text-webpack-plugin 实现提取公用 css 为单独文件,
let configPlugins = [ new HappyPack({ id: 'js', // @see threadPool: HappyThreadPool, loaders: ['babel-loader'] }), new HappyPack({ id: 'styles', threadPool: HappyThreadPool, loaders: ['style-loader', 'css-loader', 'less-loader', 'postcss-loader'] }), new webpack.optimize.CommonsChunkPlugin({ name: 'common' }), // @see new ExtractTextPlugin({ filename: 'css/[name].css?[contenthash:8]', allChunks: true }) ]; entryHtml.forEach(function (v) { configPlugins.push(new HtmlWebpackPlugin(v)); }); // webpack 配置 plugins: configPlugins,
开发
webpack-dev-server 实现开发环境自动刷新等功能
// webpack 配置 devServer: { contentBase: [ path.join(ROOT, 'src/') ], hot: false, host: '0.0.0.0', port: 8080 }
开发
npm start
http://localhost:8080/view
构建
cross-env 实现区分开发和生产环境构建
命令 | 说明 |
---|---|
npm run dev |
开发环境构建,不压缩代码 |
npm run build | rrreeemodule |
rrreee
View디렉토리 대응에 따라 js에 해당하는 html 항목을 가져옵니다.
rrreee
plugins
rrreee🎜Development🎜🎜🎜webpack-dev-server는 개발 환경 자동 새로 고침🎜🎜rrreee🎜Development🎜rrreee🎜🎜http과 같은 기능을 구현합니다. //localhost:8080/view🎜🎜 🎜Build🎜🎜🎜cross-env는 개발 환경과 프로덕션 환경의 구별을 구현합니다. build🎜🎜happypack 멀티스레딩을 사용하여 빌드 속도를 높이고 CommonsChunkPlugin은 공개 js를 별도의 파일로 추출하여 추출합니다. -text-webpack -plugin은 공개 CSS를 별도의 파일로 추출하는 기능을 구현하고,
명령 | 지침 | 🎜 thead>
---|---|
위 내용은 webpack으로 구현된 다중 항목 프로젝트 스캐폴딩의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

HTML의 미래는 무한한 가능성으로 가득합니다. 1) 새로운 기능과 표준에는 더 많은 의미 론적 태그와 WebComponents의 인기가 포함됩니다. 2) 웹 디자인 트렌드는 반응적이고 접근 가능한 디자인을 향해 계속 발전 할 것입니다. 3) 성능 최적화는 반응 형 이미지 로딩 및 게으른로드 기술을 통해 사용자 경험을 향상시킬 것입니다.

웹 개발에서 HTML, CSS 및 JavaScript의 역할은 다음과 같습니다. HTML은 컨텐츠 구조를 담당하고 CSS는 스타일을 담당하며 JavaScript는 동적 동작을 담당합니다. 1. HTML은 태그를 통해 웹 페이지 구조와 컨텐츠를 정의하여 의미를 보장합니다. 2. CSS는 선택기와 속성을 통해 웹 페이지 스타일을 제어하여 아름답고 읽기 쉽게 만듭니다. 3. JavaScript는 스크립트를 통해 웹 페이지 동작을 제어하여 동적 및 대화식 기능을 달성합니다.

Htmlisnotaprogramminglanguage; itisamarkuplanguage.1) htmlstructuresandformatswebcontentusingtags.2) itworksporstylingandjavaScriptOfforIncincivity, WebDevelopment 향상.

HTML은 웹 페이지 구조를 구축하는 초석입니다. 1. HTML은 컨텐츠 구조와 의미론 및 사용 등을 정의합니다. 태그. 2. SEO 효과를 향상시키기 위해 시맨틱 마커 등을 제공합니다. 3. 태그를 통한 사용자 상호 작용을 실현하려면 형식 검증에주의를 기울이십시오. 4. 자바 스크립트와 결합하여 동적 효과를 달성하기 위해 고급 요소를 사용하십시오. 5. 일반적인 오류에는 탈수 된 레이블과 인용되지 않은 속성 값이 포함되며 검증 도구가 필요합니다. 6. 최적화 전략에는 HTTP 요청 감소, HTML 압축, 시맨틱 태그 사용 등이 포함됩니다.

HTML은 웹 페이지를 작성하는 데 사용되는 언어로, 태그 및 속성을 통해 웹 페이지 구조 및 컨텐츠를 정의합니다. 1) HTML과 같은 태그를 통해 문서 구조를 구성합니다. 2) 브라우저는 HTML을 구문 분석하여 DOM을 빌드하고 웹 페이지를 렌더링합니다. 3) 멀티미디어 기능을 향상시키는 HTML5의 새로운 기능. 4) 일반적인 오류에는 탈수 된 레이블과 인용되지 않은 속성 값이 포함됩니다. 5) 최적화 제안에는 시맨틱 태그 사용 및 파일 크기 감소가 포함됩니다.

WebDevelopmentReliesonHtml, CSS 및 JavaScript : 1) HtmlStructuresContent, 2) CSSSTYLESIT, 및 3) JAVASCRIPTADDSINGINTERACTIVITY, BASISOFMODERNWEBEXPERIENCES를 형성합니다.

HTML의 역할은 태그 및 속성을 통해 웹 페이지의 구조와 내용을 정의하는 것입니다. 1. HTML은 읽기 쉽고 이해하기 쉽게하는 태그를 통해 컨텐츠를 구성합니다. 2. 접근성 및 SEO와 같은 시맨틱 태그 등을 사용하십시오. 3. HTML 코드를 최적화하면 웹 페이지로드 속도 및 사용자 경험이 향상 될 수 있습니다.

"Code"는 "Code"BroadlyIncludeLugageslikeJavaScriptandPyThonforFunctureS (htMlisAspecificTypeofCodeFocudecturecturingWebContent)


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

에디트플러스 중국어 크랙 버전
작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

WebStorm Mac 버전
유용한 JavaScript 개발 도구

안전한 시험 브라우저
안전한 시험 브라우저는 온라인 시험을 안전하게 치르기 위한 보안 브라우저 환경입니다. 이 소프트웨어는 모든 컴퓨터를 안전한 워크스테이션으로 바꿔줍니다. 이는 모든 유틸리티에 대한 액세스를 제어하고 학생들이 승인되지 않은 리소스를 사용하는 것을 방지합니다.

SublimeText3 영어 버전
권장 사항: Win 버전, 코드 프롬프트 지원!

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경
