phép nói rằng theres một gói trong node_modules
gọi foo và tôi muốn nhập một mô-đun trong một thư viện như foo/module
qua webpack & babel ...Làm cách nào để nhập mô-đun trong thư mục con gói npm với gói webpack?
import Foo from 'foo';
làm việc
import SomeOtherModule from 'foo/module';
không thành công với những điều sau đây:
Module not found: Error: Cannot resolve module 'foo/module' in /Users/x/Desktop/someproject/js
Điều này làm cho webpack tìm kiếm tệp sai địa điểm thay vì node_modules
webpack.config của tôi trông như thế này:
var webpack = require('webpack');
var path = require('path');
module.exports = {
entry: ['babel-polyfill','./js/script.js'],
output: {
path: __dirname,
filename: './build/script.js'
},
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel',
query: {
cacheDirectory: true,
presets: ['es2015']
}
}
],
},
plugins: [
new webpack.NoErrorsPlugin()
],
stats: {
colors: true
},
devtool: 'source-map'
};
Hiển thị cấu trúc tệp và thư mục cho mô-đun foo, vui lòng –