angular - 'ng build' move scripts to subfolder -
ng build exports files dist folder follow
index.html main.bundle.js styles.bundle.js ... i want scripts in subfolder
*index.html scripts/main.bundle.js scripts/styles.bundle.js ...* how can it?
- run
ng eject -ec(add '-prod' production build, or-aot falsejit build). command expose webpack.config.js file in root directory.-ecflag extract css files (instead of serving them js file). (to 'uneject' app again see another answer) run
npm installin order install webpack loadersin webpack.config.js file edit output entry , add desired directory name js files:
"output": { "path": path.join(process.cwd(), "dist"), "filename": "scripts/[name].[chunkhash:20].bundle.js", "chunkfilename": "scripts/[id].[chunkhash:20].chunk.js" }because added
-ecflagng ejectcommand, have css file(s) well. can move dist/styles modifying extracttextplugin plugin under plugins entry in webpack.config.js file:new extracttextplugin({ "filename": "styles/[name].[contenthash:20].bundle.css", "disable": false }),run
npm run buildsinceng buildno longer works on ejected apps. should dist directory scripts , styles directories inside along js/css files, index.html should located directly under dist , have correct includes like:<link href="styles/styles.d41d8cd98f00b204e980.bundle.css" rel="stylesheet"/> <script type="text/javascript" src="scripts/inline.3d27fc24e48981450c35.bundle.js"></script>
Comments
Post a Comment