Tôi đang sử dụng this tutorial để thiết lập dự án React.js bằng gói webpack. Webpack.config.js bên dưới gần như là bản sao chính xác (ngoại trừ việc tôi đang sử dụng thư mục app
và 'dist'), và tôi cũng thêm d3.js làm external
. Vì React được thêm vào là external
, nó cho phép tôi làm require('react')
trong bất kỳ tệp ứng dụng nào của tôi mà không bao gồm nó trong gói. Tôi muốn làm tương tự với d3.js
và đã cài đặt nó như là một node_module, và liệt kê nó trong khu vực bên ngoài của cấu hình webpack của tôi, nhưng khi tôi làm require('d3')
tôi nhận được một thông báo lỗi rằng nó không có sẵn.sử dụng d3.js làm bên ngoài trong gói web
Làm cách nào tôi có thể sử dụng d3
(hoặc jQuery cho vấn đề đó) làm bên ngoài nếu tôi đã cài đặt nó làm nút_module?
này được thiết lập dự án của tôi
/app
/dist
/node_modules
package.json
webpack.config.js
module.exports = { entry: './app/index.jsx', output: { path: './dist', filename: 'bundle.js', //this is the default name, so you can skip it //at this directory our bundle file will be available //make sure port 8090 is used when launching webpack-dev-server publicPath: 'http://localhost:8090/assets' }, module: { loaders: [ { //tell webpack to use jsx-loader for all *.jsx files test: /\.jsx$/, loader: 'jsx-loader?insertPragma=React.DOM&harmony' } ] }, externals: { //don't bundle the 'react' npm package with our bundle.js //but get it from a global 'React' variable 'react': 'React', 'd3': 'd3' }, resolve: { modulesDirectories: ['app', 'node_modules'], extensions: ['', '.js', '.jsx'] } }
Bạn có thể giúp tôi tìm câu trả lời cho câu hỏi rất giống này không: https://stackoverflow.com/questions/37912988/how-to-load-c3js-properly-into-webpack? – PedroD