miterial-components-web.css를 index.html 파일 헤더에 추가했습니다.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 구성 요소를 추가했습니다. 이제는 모든 webpack을 내 번들에 추가 할 수있게되었습니다 .js.
import 'material-components-web/dist/material-components-web.js';
오류는 발생시키지 않았지만 스타일을로드하지 않았습니다. 문제가 뭐야?
안부
내 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'); 이제는 corretly로로드되지만 window.mdc.autoInit()는 mdc를 알지 못했습니다! 스크립트를 올바르게로드하려면 어떻게해야합니까? 원래 webpack.config 파일을 붙여 넣습니다. – bluelemonade
config를 보면 번들 된 코드가'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에는 스크립트 태그가 없습니다. webpack이 작업을 수행하기 때문에 너를 위해서. –