1

i am new to webpack, i have configured webpack to a working condition where my index.html file and budle.js file comes to /dist folder. iam aware that i can build css files too but for now i want to build js and run the app. please check the attached images for better understanding of the directory structure and the webpack build configuration. enter image description here

enter image description here

My doubt is that if i run app from dist folder i would lose all the path of angular templates and image paths etc. how can i overcome this situation? any help is appreciated.

1
  • Hi Rameez. Regarding your answer here, would you repair it and undelete it? I shall undownvote if so. The all-caps shouting and txtspk "plz" are easy to fix, and it seems unnecessary to lose the content. Commented Sep 26, 2017 at 8:55

1 Answer 1

1

First of all, you need to know that the goal is to have a fully runnable stand alone application inside ./dist/ after build. All sourcefiles which are needed to run your application should be placed there. In that way you will be able to distribute your application by copy/upload/or-what-ever based on your ./dist/ directory. All other directories in your project are just for development. Those will be not a part of your distribution package.

Wrong approach: Trying to change the include path's in your application.

You need to copy or concat your sourcefiles (static files) into your distribution folder. I realy don't know why your views/templates are not stored in ./app/assets/ and not in ./app/views/ because ./app/views/ should be the correct path to store your views. Well, you need to copy your static sourcefiles. For example: You could use copy-webpack-plugin.

Your webpack config could look like this in the end:

var CopyWebpackPlugin = require('copy-webpack-plugin');
var path = require('path');

module.exports = {
  context: path.join(__dirname, 'app'),
  devServer: {
    // This is required for older versions of webpack-dev-server
    // if you use absolute 'to' paths. The path should be an
    // absolute path to your build destination.
    outputPath: path.join(__dirname, 'dist')
  },
  plugins: [
    new CopyWebpackPlugin([
      {
        from: 'assets/**/*',
        to: 'assets/'
      },
      {
        from: 'views/**/*',
        to: 'views/'
      },
    ], {
      ignore: [
      ],

      // By default, we only copy modified files during
      // a watch or webpack-dev-server build. Setting this
      // to `true` copies all files.
      copyUnmodified: true
    })
  ]
};
Sign up to request clarification or add additional context in comments.

6 Comments

sorry for the confusion in image.. html files in asset folder are given by html developer , i have stored all angular html templates in aossiative modules folder or views folder.
@RameezRami Ok, updated my answer. Sorry, I cant give you a full runnable webpack config. This is just a approach. Does it help you?
Now the next problem is now i also have to copy my "/components" , "/directives" like folders to dist right? i cant fully copy all directories because the JS files in those folder have been already added.. do you know of any method to filter by only html files with copy-webpack-plugin
@RameezRami You need to copy all your static files which were not imported via required() in your webpack config. You can copy all HTML files by using components/**/*.html. I hope this will help you to fix your problems. Glad to help ya. You may going to read the basics about using WebPack. Those basic FAQs will help you alot.
Thanks you very much lin.. i really appreaciate the effort you put to help me. Also your sample code works like charm.. i forgot to set config.context = path.join(__dirname, 'app'); thats why it didnt work.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.