私のindex.htmlファイルのヘッダにmterial-components-web.cssを追加しました。webpack経由でmaterial-components-web.cssを追加します。
<script src="node_modules/material-components-web/dist/material-components-web.js"></script>
<script src="dist/bundle.js"></script>
cssコンポーネントがうまく機能します。今度はwebpack経由でいくつかのjavscriptコンポーネントを追加しました。今、あなたは私のbundle.jsにすべてのwebpackを追加することができますthouhgt。
import 'material-components-web/dist/material-components-web.js';
エラーはありませんが、スタイルはロードされません!うん、問題?
について
my webpackの設定です。
const path = require('path');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
module.exports = {
entry: './src/app.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'sass-loader']
})
}
]
},
plugins: [
new ExtractTextPlugin('style.css')
],
devServer: {
contentBase: "./build"
}
};
私はrequire( './../node_modules/material-components-web/dist/material-components-web.js')に切り替わります。今度はそれが確実に読み込まれますが、window.mdc.autoInit()はmdcを知らなかったのです!スクリプトを正しく読み込むにはどうすればよいですか?私は元の投稿に私のwebpack.configを貼り付けます。 – bluelemonade
設定を見ると、バンドルされたコードは 'dist'フォルダに置かれます。 devServerは 'build'から提供されていますか? 'index.html'はwebpackによって処理されません。これは、スクリプト(つまり、webpack: 'bundle.js'にバンドルされているもの)を含めることを希望することを意味しますが、' html-webpack-pugin'を使用することをお勧めします。 index.htmlを 'dist'に設定し、スクリプトタグも挿入してください。https://webpack.js.org/plugins/html-webpack-plugin/ https://github.com/rakcheru/webpack-bootstrap/blob /master/webpack.config.js –
ご覧のとおり、https://github.com/rakcheru/webpack-bootstrap/blob/master/src/index.htmlにはスクリプトタグはありません。あなたのために。 –