Vì vậy, tôi đang cố gắng xây dựng một ứng dụng bản đồ bằng cách sử dụng webpack
và leaflet
. Tôi có thể yêu cầu leaflet.js
từ tệp map.js
của tôi, nhưng tôi không thể gọi leaflet.css mà không gặp lỗi.webpack - yêu cầu ('node_modules/leaflet/leaflet.css')
My hiện webpack.config.js
trông giống như:
'use strict'
var webpack = require('webpack'),
path = require('path'),
HtmlWebpackPlugin = require('html-webpack-plugin'),
srcPath = path.join(__dirname, 'src');
module.exports = {
target: "web",
cache: true,
entry: {
app: path.join(srcPath, "index.js")
},
resolve: {
alais: {
leaflet_css: __dirname + "/node_modules/leaflet/dist/leaflet.css"
}
},
module: {
loaders: [
{test: /\.js?$/, exclude: /node_modules/, loader: "babel-loader"},
{test: /\.scss?$/, exclude: /node_modules/, loader: "style!css!sass!"},
{test: /\.css?$/, loader: "style!css!"}
]
},
plugins: [
new webpack.optimize.CommonsChunkPlugin("common", "common.js"),
new HtmlWebpackPlugin({
inject: true,
template: "src/index.html"
}),
new webpack.NoErrorsPlugin()
],
output: {
path: path.join(__dirname, "dist"),
publicPath: "/dist/",
filename: "[name].js",
pathInfo: true
}
}
Và tập tin main.js
của tôi trông giống như:
var $ = require('jquery'),
leaflet = require('leaflet');
require("./sass/main.scss");
require("leaflet_css");
var map = L.map('map').setView([51.505, -0.09], 13);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
L.marker([51.5, -0.09]).addTo(map)
.bindPopup('A pretty CSS3 popup.<br> Easily customizable.')
.openPopup();
console.log('I got called');
cách tiếp cận đúng đắn về bundling file css từ nhà cung cấp bên thứ 3 thông qua webpack là gì?
tôi thấy this project được leaflet
được lưu trữ trong thư mục libs ... lý do cho điều này là những gì, tại sao lưu nó trong thư mục libs
nếu nó được cài đặt vào node_modules
direcory qua npm
?
Đây là bài tập học tập rất nhiều nên mọi con trỏ đều được đánh giá cao! :)
có thể trùng lặp của [Ví dụ về làm thế nào để tải file CSS tĩnh từ nút \ _modules sử dụng webpack?] (Http://stackoverflow.com/questions/34311656/example -of-how-to-load-static-css-files-from-node-modules-using-webpack) – Drew
@Drew - Câu hỏi này đã được đăng trước đó - ví dụ của bạn là bản sao. Thật không may tôi không có đủ quyền truy cập để làm cho nó như vậy. – hloughrey