我试图创建一个可重用的NPM模块。我遵循的教程说我需要dist
文件夹中的package.json
文件。所以起初我只是将package.json
文件从我的项目的根目录复制到dist文件夹中,一切都很好。npm包:package.json处理
问题是,当涉及到源代码控制时,您确实不希望在dist
文件夹中检入任何内容,所以我所做的是在我的项目的根目录中创建一个package.dist.json
文件,然后在构建步骤将其复制到dist
文件夹并重新命名。
这不起作用。这里是我的构建脚本:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"transpile": "ngc",
"package": "rollup -c",
"minify": "uglifyjs dist/bundles/test-service.umd.js --screw-ie8 --compress --mangle --comments --output dist/bundles/test-service.umd.min.js",
"build": "copyfiles package.dist.json dist && rename dist/package.dist.json dist/package.json && npm run transpile && npm run package && npm run minify && npm pack dist/"
},
这里是我的devDependencies:
"devDependencies": {
"@angular/compiler": "^4.0.0",
"@angular/compiler-cli": "^4.0.0",
"rollup": "^0.47.4",
"typescript": "^2.4.2",
"uglify-js": "^3.0.27",
"copyfiles": "^1.0.0",
"rename-cli": "^4.0.0"
},
这不是工作,我得到一个错误说:
该命令的语法不正确。
我甚至不确定这是否是最好的方法。有更好的方法吗?如果没有,为什么我的build
任务不工作?
这里是rollup.config.js:
import angularInline from 'rollup-plugin-angular-inline';
export default {
entry: 'dist/hello-world.js',
dest: 'dist/bundles/hello-world.umd.js',
sourceMap: 'inline',
format: 'umd',
moduleName: 'hello-world-app',
globals: {
'@angular/core': 'ng.core',
'@angular/router': 'ng.router'
},
plugins: [
angularInline({
include: './dist/src/**/*.component.js'
})
],
external: ['@angular/core', '@angular/router'],
treeshake: true
}
您另外一个脚本必须畸形。你能否用你的全部包裹更新你的问题。json'scripts'(minify,transpile,等) –
我已经用所有脚本更新了我的问题。 – Zeus82
你也介意发布你的rollup.config文件。 –