Concept
webpack は、最新の JavaScript アプリケーション用のモジュール バンドラーです。
webpack がアプリケーションを処理するとき、依存関係グラフ (アプリケーションが必要とするすべてのモジュールを含む) を再帰的に構築し、これらのモジュールをいくつかの Budle ファイル (通常は 1 つだけ、プロジェクトに応じてブラウザーによってロードされます) にパッケージ化します。条件)。
これは素晴らしい構成ですが、始める前に、エントリー、出力、ローダー、プラグインという 4 つの中心的な概念を理解するだけで済みます。
設定オブジェクト オプション
webpack.config.js
const path = require('path'); module.exports = { // click on the name of the option to get to the detailed documentation // click on the items with arrows to show more examples / advanced options entry: "./app/entry", // string | object | array // Here the application starts executing // and webpack starts bundling output: { // options related to how webpack emits results path: path.resolve(__dirname, "dist"), // string // the target directory for all output files // must be an absolute path (use the Node.js path module) filename: "bundle.js?1.1.11", // string // the filename template for entry chunks publicPath: "/assets/", // string // the url to the output directory resolved relative to the HTML page library: "MyLibrary", // string, // the name of the exported library libraryTarget: "umd", // universal module definition // the type of the exported library /* Advanced output configuration (click to show) */ }, module: { // configuration regarding modules rules: [ // rules for modules (configure loaders, parser options, etc.) { test: /\.jsx?$/, include: [ path.resolve(__dirname, "app") ], exclude: [ path.resolve(__dirname, "app/demo-files") ], // these are matching conditions, each accepting a regular expression or string // test and include have the same behavior, both must be matched // exclude must not be matched (takes preferrence over test and include) // Best practices: // - Use RegExp only in test and for filename matching // - Use arrays of absolute paths in include and exclude // - Try to avoid exclude and prefer include issuer: { test, include, exclude }, // conditions for the issuer (the origin of the import) enforce: "pre", enforce: "post", // flags to apply these rules, even if they are overridden (advanced option) loader: "babel-loader", // the loader which should be applied, it'll be resolved relative to the context // -loader suffix is no longer optional in webpack2 for clarity reasons // see webpack 1 upgrade guide options: { presets: ["es2015"] }, // options for the loader }, { test: "\.html$", use: [ // apply multiple loaders and options "htmllint-loader", { loader: "html-loader", options: { /* ... */ } } ] }, { oneOf: [ /* rules */ ] }, // only use one of these nested rules { rules: [ /* rules */ ] }, // use all of these nested rules (combine with conditions to be useful) { resource: { and: [ /* conditions */ ] } }, // matches only if all conditions are matched { resource: { or: [ /* conditions */ ] } }, { resource: [ /* conditions */ ] }, // matches if any condition is matched (default for arrays) { resource: { not: /* condition */ } } // matches if the condition is not matched ], /* Advanced module configuration (click to show) */ }, resolve: { // options for resolving module requests // (does not apply to resolving to loaders) modules: [ "node_modules", path.resolve(__dirname, "app") ], // directories where to look for modules extensions: [".js?1.1.11", ".json", ".jsx", ".css?1.1.11"], // extensions that are used alias: { // a list of module name aliases "module": "new-module", // alias "module" -> "new-module" and "module/path/file" -> "new-module/path/file" "only-module$": "new-module", // alias "only-module" -> "new-module", but not "module/path/file" -> "new-module/path/file" "module": path.resolve(__dirname, "app/third/module.js?1.1.11"), // alias "module" -> "./app/third/module.js?1.1.11" and "module/file" results in error // modules aliases are imported relative to the current context }, /* alternative alias syntax (click to show) */ /* Advanced resolve configuration (click to show) */ }, performance: { hints: "warning", // enum maxAssetSize: 200000, // int (in bytes), maxEntrypointSize: 400000, // int (in bytes) assetFilter: function(assetFilename) { // Function predicate that provides asset filenames return assetFilename.endsWith('.css') || assetFilename.endsWith('.js'); } }, devtool: "source-map", // enum // enhance debugging by adding meta info for the browser devtools // source-map most detailed at the expense of build speed. context: __dirname, // string (absolute path!) // the home directory for webpack // the entry and module.rules.loader option // is resolved relative to this directory target: "web", // enum // the environment in which the bundle should run // changes chunk loading behavior and available modules externals: ["react", /^@angular\//], // Don't follow/bundle these modules, but request them at runtime from the environment stats: "errors-only", // lets you precisely control what bundle information gets displayed devServer: { proxy: { // proxy URLs to backend development server '/api': 'http://localhost:3000' }, contentBase: path.join(__dirname, 'public'), // boolean | string | array, static file location compress: true, // enable gzip compression historyApiFallback: true, // true for index.html upon 404, object for multiple paths hot: true, // hot module replacement. Depends on HotModuleReplacementPlugin https: false, // true for self-signed, object for cert authority noInfo: true, // only errors & warns on hot reload // ... }, plugins: [ // ... ], // list of additional plugins /* Advanced configuration (click to show) */ }
このドキュメントの目的は、詳細な概念の特定の使用例へのリンクを提供しながら、これらの概念の高レベルの概要を提供することです。
Entry
webpack は、すべてのアプリケーションの依存関係グラフを作成します。この依存関係グラフの開始点は、既知のエントリ ポイントです。このエントリ ポイントは、既知の依存関係グラフに基づいて webpack をどこから開始してパッケージ化するかを指示します。アプリケーションのエントリ ポイントは、コンテキスト ルート、またはアプリケーションを開始する最初のファイルと考えることができます。
webpack設定オブジェクトのentry属性でエントリポイントを定義します。簡単な例は次のとおりです。
module.exports = { entry: './path/to/my/entry/file.js' };
エントリ属性を宣言するにはいくつかの方法があります:
1. 単一エントリの構文
const config = { entry: './path/to/my/entry/file.js' }; module.exports = config;
2. 複数ページのアプリケーション
const config = { entry: { app: './src/app.js', vendors: './src/vendors.js' } };
出力
すべてのコードをパッケージ化したら、webpack にそれをパッケージ化する場所を指示する必要があります。出力属性は、コードの処理方法を webpack に指示します。
const config = { entry: { pageOne: './src/pageOne/index.js', pageTwo: './src/pageTwo/index.js', pageThree: './src/pageThree/index.js' } };
上記の例では、
属性を使用して webpack にパッケージ化されたファイルの名前とパスを伝えますoutput.filename
和output.path
その他の設定項目
Loaders
この設定項目の目的は、webpack があなたのファイルのすべてのコードに注目できるようにすることです。ブラウザではなくプロジェクトを使用します (これは、それらが一緒にパッケージ化されるという意味ではありません)。 webpack は、各ファイル (.css、.html、.scss、.jpg など) をモジュールとして扱います。ただし、webpack は JavaScript しか認識しません。
webpack のローダーは、これらのファイルをモジュールに変換し、依存関係グラフに追加します。
大まかに言うと、Webpack 設定には 2 つの目的があります:
1. 特定のローダーで変換する必要があるファイルを特定します。2. 変換されたファイルは依存関係グラフに追加できます。
const path = require('path'); module.exports = { entry: './path/to/my/entry/file.js', output: { path: path.resolve(__dirname, 'dist'), filename: 'my-first-webpack.bundle.js' } };
上記の設定では、別のモジュールの rulues 属性が定義されています。このモジュールには、test と use の 2 つの属性があります。これにより、webpack に次のものをコンパイルするように指示されます: require() または import ステートメントを使用する場合、パスに .js または .jsx 接尾辞を持つファイルは、babel-loader を使用して変換され、パッケージ化されます。
その他の設定項目
プラグイン
ローダーはファイルごとにのみ変換を実行するため、動作を最適化するためにプラグインが最も一般的に使用されます(ただし、これに限定されません)。また、プラグインの編集またはブロックで機能をカスタマイズできます。パッケージ化されたモジュール 中 (など)。
webpack プラグイン システムは非常に強力でカスタマイズ可能です。
プラグインを使用するには、require() して plugins 配列に追加するだけです。オプションを使用してさらに多くのプラグインをカスタマイズできます。プラグインは構成内でさまざまな目的に複数回使用できるため、新しいインスタンスを作成する必要があります。
const path = require('path'); const config = { entry: './path/to/my/entry/file.js', output: { path: path.resolve(__dirname, 'dist'), filename: 'my-first-webpack.bundle.js' }, module: { rules: [ {test: /\.(js|jsx)$/, use: 'babel-loader'} ] } }; module.exports = config;
webpack は、すぐに使えるプラグインを多数提供しています。詳細については、プラグイン リストから入手できます。
Webpack 構成でプラグインを使用するのは簡単ですが、さらに検討する価値のある使用法がたくさんあります。
その他の設定項目
簡単な例
const HtmlWebpackPlugin = require('html-webpack-plugin'); //installed via npm const webpack = require('webpack'); //to access built-in plugins const path = require('path'); const config = { entry: './path/to/my/entry/file.js', output: { path: path.resolve(__dirname, 'dist'), filename: 'my-first-webpack.bundle.js' }, module: { rules: [ {test: /\.txt$/, use: 'raw-loader'} ] }, plugins: [ new webpack.optimize.UglifyJsPlugin(), new HtmlWebpackPlugin({template: './src/index.html'}) ] }; module.exports = config;
以上がWebpack パッケージャーの簡単な紹介の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

さまざまなJavaScriptエンジンは、各エンジンの実装原則と最適化戦略が異なるため、JavaScriptコードを解析および実行するときに異なる効果をもたらします。 1。語彙分析:ソースコードを語彙ユニットに変換します。 2。文法分析:抽象的な構文ツリーを生成します。 3。最適化とコンパイル:JITコンパイラを介してマシンコードを生成します。 4。実行:マシンコードを実行します。 V8エンジンはインスタントコンピレーションと非表示クラスを通じて最適化され、Spidermonkeyはタイプ推論システムを使用して、同じコードで異なるパフォーマンスパフォーマンスをもたらします。

現実世界におけるJavaScriptのアプリケーションには、サーバー側のプログラミング、モバイルアプリケーション開発、モノのインターネット制御が含まれます。 2。モバイルアプリケーションの開発は、ReactNativeを通じて実行され、クロスプラットフォームの展開をサポートします。 3.ハードウェアの相互作用に適したJohnny-Fiveライブラリを介したIoTデバイス制御に使用されます。

私はあなたの日常的な技術ツールを使用して機能的なマルチテナントSaaSアプリケーション(EDTECHアプリ)を作成しましたが、あなたは同じことをすることができます。 まず、マルチテナントSaaSアプリケーションとは何ですか? マルチテナントSaaSアプリケーションを使用すると、Singの複数の顧客にサービスを提供できます

この記事では、許可によって保護されたバックエンドとのフロントエンド統合を示し、next.jsを使用して機能的なedtech SaaSアプリケーションを構築します。 FrontEndはユーザーのアクセス許可を取得してUIの可視性を制御し、APIリクエストがロールベースに付着することを保証します

JavaScriptは、現代のWeb開発のコア言語であり、その多様性と柔軟性に広く使用されています。 1)フロントエンド開発:DOM操作と最新のフレームワーク(React、Vue.JS、Angularなど)を通じて、動的なWebページとシングルページアプリケーションを構築します。 2)サーバー側の開発:node.jsは、非ブロッキングI/Oモデルを使用して、高い並行性とリアルタイムアプリケーションを処理します。 3)モバイルおよびデスクトップアプリケーション開発:クロスプラットフォーム開発は、反応および電子を通じて実現され、開発効率を向上させます。

JavaScriptの最新トレンドには、TypeScriptの台頭、最新のフレームワークとライブラリの人気、WebAssemblyの適用が含まれます。将来の見通しは、より強力なタイプシステム、サーバー側のJavaScriptの開発、人工知能と機械学習の拡大、およびIoTおよびEDGEコンピューティングの可能性をカバーしています。

JavaScriptは現代のWeb開発の基礎であり、その主な機能には、イベント駆動型のプログラミング、動的コンテンツ生成、非同期プログラミングが含まれます。 1)イベント駆動型プログラミングにより、Webページはユーザー操作に応じて動的に変更できます。 2)動的コンテンツ生成により、条件に応じてページコンテンツを調整できます。 3)非同期プログラミングにより、ユーザーインターフェイスがブロックされないようにします。 JavaScriptは、Webインタラクション、シングルページアプリケーション、サーバー側の開発で広く使用されており、ユーザーエクスペリエンスとクロスプラットフォーム開発の柔軟性を大幅に改善しています。

Pythonはデータサイエンスや機械学習により適していますが、JavaScriptはフロントエンドとフルスタックの開発により適しています。 1. Pythonは、簡潔な構文とリッチライブラリエコシステムで知られており、データ分析とWeb開発に適しています。 2。JavaScriptは、フロントエンド開発の中核です。 node.jsはサーバー側のプログラミングをサポートしており、フルスタック開発に適しています。


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

VSCode Windows 64 ビットのダウンロード
Microsoft によって発売された無料で強力な IDE エディター

SublimeText3 Linux 新バージョン
SublimeText3 Linux 最新バージョン

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

SublimeText3 英語版
推奨: Win バージョン、コードプロンプトをサポート!

AtomエディタMac版ダウンロード
最も人気のあるオープンソースエディター
