我从bash运行npm run build
,目标文件夹(lib
)不包含任何文件。
这是我的webpack.config-build.js文件:
var path = require('path');
var webpack = require("webpack");
const TARGET = process.env.npm_lifecycle_event;
module.exports = {
entry: [path.join(__dirname, '/src/index.js')],
module: {
rules: [{
test: /\.js?$/,
use: ['babel-loader'],
include: path.join(__dirname, '/src')
}]
},
output: {
filename: 'index.js',
path: path.resolve(__dirname, '/lib')
},
plugins: [
new webpack.IgnorePlugin(/react\/addons/),
new webpack.IgnorePlugin(/react\/lib\/ReactContext/),
new webpack.IgnorePlugin(/react\/lib\/ExecutionEnvironment/)
],
target: 'node'
};
这是运行命令后的输出(无错误):
Hash: 9e969aec2448315372a9
Version: webpack 2.2.1
Time: 3121ms
Asset Size Chunks Chunk Names
index.js 2.67 MB 0 [emitted] [big] main
[15] ./~/react/react.js 56 bytes {0} [built]
[121] ./~/enzyme/build/ReactWrapper.js 40 kB {0} [built]
[123] ./~/enzyme/build/ShallowWrapper.js 42.7 kB {0} [built]
[140] ./~/intl-messageformat/index.js 553 bytes {0} [built]
[213] ./src/index.js 2.43 kB {0} [built]
[238] ./~/enzyme/build/index.js 973 bytes {0} [built]
[239] ./~/enzyme/build/mount.js 549 bytes {0} [built]
[240] ./~/enzyme/build/render.js 1.04 kB {0} [built]
[241] ./~/enzyme/build/shallow.js 544 bytes {0} [built]
[264] ./~/graceful-fs/graceful-fs.js 6.94 kB {0} [optional] [built]
[272] ./~/intl-format-cache/index.js 110 bytes {0} [built]
[293] ./~/jsonfile/index.js 3.13 kB {0} [built]
[470] ./~/react-intl/lib/index.es.js 55 kB {0} [built]
[471] ./~/react-intl/locale-data/index.js 290 kB {0} [built]
[494] multi ./src/index.js 28 bytes {0} [built]
+ 480 hidden modules
答案 0 :(得分:1)
问题是您将输出路径设置为/lib
,即文件系统的根目录,而不是当前目录中的lib
。原因是path.resolve
将/lib
视为绝对路径。除非你以root身份运行它,否则通常会抛出一个权限被拒绝的错误。将输出路径更改为:
path: path.resolve(__dirname, 'lib')