├── app ├── variables.scss ├── main.css ├── imgs │ └── avatar.jpg ├── main.scss ├── sub.js ├── plugin.js ├── mobile.js └── index.js ├── templates ├── index.html ├── mobile.html └── test.html ├── tests └── test.js ├── bower.json ├── .gitignore ├── README.md ├── package.json ├── webpack.test.config.js ├── webpack.production.config.js └── webpack.config.js /app/variables.scss: -------------------------------------------------------------------------------- 1 | $red: red; 2 | -------------------------------------------------------------------------------- /app/main.css: -------------------------------------------------------------------------------- 1 | h1 { 2 | color: red; 3 | } 4 | -------------------------------------------------------------------------------- /app/imgs/avatar.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vikingmute/webpack-basic-starter/HEAD/app/imgs/avatar.jpg -------------------------------------------------------------------------------- /app/main.scss: -------------------------------------------------------------------------------- 1 | @import "./variables.scss"; 2 | 3 | h1 { 4 | color: $red; 5 | height: 220px; 6 | background: url('./imgs/avatar.jpg') no-repeat; 7 | } 8 | -------------------------------------------------------------------------------- /app/sub.js: -------------------------------------------------------------------------------- 1 | export default function() { 2 | var element = document.createElement('h2'); 3 | element.innerHTML = "Hello h2 world hahaha"; 4 | return element; 5 | } 6 | -------------------------------------------------------------------------------- /templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |promise result is ${number}, now is ${currentTime}, lodash result is ${testArrStr}`); 35 | //call our jquery plugin! 36 | $('p').greenify(); 37 | }); 38 | -------------------------------------------------------------------------------- /webpack.test.config.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var webpack = require('webpack'); 3 | var HtmlwebpackPlugin = require('html-webpack-plugin'); 4 | 5 | var ROOT_PATH = path.resolve(__dirname); 6 | var APP_PATH = path.resolve(ROOT_PATH, 'app'); 7 | var TEST_PATH = path.resolve(ROOT_PATH, 'tests'); 8 | var TEM_PATH = path.resolve(ROOT_PATH, 'templates'); 9 | 10 | module.exports = { 11 | entry: 'mocha!./tests/test.js', 12 | output: { 13 | filename: 'test.build.js', 14 | path: TEST_PATH 15 | }, 16 | module: { 17 | loaders: [ 18 | { 19 | test: /\.jsx?$/, 20 | loader: 'babel', 21 | include: APP_PATH, 22 | query: { 23 | presets: ['es2015'] 24 | } 25 | }, 26 | { 27 | test: /\.scss$/, 28 | loaders: ['style', 'css', 'sass'], 29 | include: APP_PATH 30 | }, 31 | { 32 | test: /\.(png|jpg)$/, 33 | loader: 'url?limit=40000' 34 | } 35 | ] 36 | }, 37 | devServer: { 38 | historyApiFallback: true, 39 | hot: true, 40 | inline: true, 41 | progress: true, 42 | }, 43 | plugins: [ 44 | new HtmlwebpackPlugin({ 45 | title: 'Test case', 46 | template: path.resolve(TEM_PATH, 'test.html') 47 | }), 48 | ] 49 | } 50 | -------------------------------------------------------------------------------- /webpack.production.config.js: -------------------------------------------------------------------------------- 1 | 2 | var path = require('path'); 3 | var HtmlwebpackPlugin = require('html-webpack-plugin'); 4 | var webpack = require('webpack'); 5 | 6 | var ROOT_PATH = path.resolve(__dirname); 7 | var APP_PATH = path.resolve(ROOT_PATH, 'app'); 8 | var TEM_PATH = path.resolve(ROOT_PATH, 'templates'); 9 | var BUILD_PATH = path.resolve(ROOT_PATH, 'build'); 10 | var BOWER_PATH = path.resolve(ROOT_PATH, 'bower_components'); 11 | 12 | module.exports = { 13 | entry: { 14 | app: path.resolve(APP_PATH, 'index.js'), 15 | mobile: path.resolve(APP_PATH, 'mobile.js'), 16 | vendors: ['jquery', 'moment', 'lodash'] 17 | }, 18 | output: { 19 | path: BUILD_PATH, 20 | filename: '[name].[hash].js' 21 | }, 22 | resolve: { 23 | alias: { 24 | lodash: path.resolve(BOWER_PATH, 'lodash/lodash.js') 25 | } 26 | }, 27 | module: { 28 | loaders: [ 29 | { 30 | test: /\.jsx?$/, 31 | loader: 'babel', 32 | include: APP_PATH, 33 | query: { 34 | presets: ['es2015'] 35 | } 36 | }, 37 | { 38 | test: /\.scss$/, 39 | loaders: ['style', 'css', 'sass'], 40 | include: APP_PATH 41 | }, 42 | { 43 | test: /\.(png|jpg)$/, 44 | loader: 'url?limit=40000' 45 | } 46 | ] 47 | }, 48 | plugins: [ 49 | //enable uglify 50 | new webpack.optimize.UglifyJsPlugin({minimize: true}), 51 | //split vendors script 52 | new webpack.optimize.CommonsChunkPlugin('vendors', 'vendors.js'), 53 | //generate two pages 54 | new HtmlwebpackPlugin({ 55 | title: 'Hello World app', 56 | template: path.resolve(TEM_PATH, 'index.html'), 57 | filename: 'index.html', 58 | chunks: ['app', 'vendors'], 59 | inject: 'body' 60 | }), 61 | new HtmlwebpackPlugin({ 62 | title: 'Hello Mobile app', 63 | template: path.resolve(TEM_PATH, 'mobile.html'), 64 | filename: 'mobile.html', 65 | chunks: ['mobile', 'vendors'], 66 | inject: 'body' 67 | }) 68 | //provide $, jQuery and window.jQuery to every script 69 | /*new webpack.ProvidePlugin({ 70 | $: "jquery", 71 | jQuery: "jquery", 72 | "window.jQuery": "jquery" 73 | })*/ 74 | ] 75 | }; 76 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | 2 | var path = require('path'); 3 | var webpack = require('webpack'); 4 | var HtmlwebpackPlugin = require('html-webpack-plugin'); 5 | 6 | var ROOT_PATH = path.resolve(__dirname); 7 | var APP_PATH = path.resolve(ROOT_PATH, 'app'); 8 | var BUILD_PATH = path.resolve(ROOT_PATH, 'build'); 9 | var TEM_PATH = path.resolve(ROOT_PATH, 'templates'); 10 | var BOWER_PATH = path.resolve(ROOT_PATH, 'bower_components'); 11 | 12 | module.exports = { 13 | entry: { 14 | app: path.resolve(APP_PATH, 'index.js'), 15 | mobile: path.resolve(APP_PATH, 'mobile.js'), 16 | vendors: ['jquery', 'moment', 'lodash'] 17 | }, 18 | output: { 19 | path: BUILD_PATH, 20 | filename: '[name].js' 21 | }, 22 | resolve: { 23 | alias: { 24 | lodash: path.resolve(BOWER_PATH, 'lodash/lodash.js') 25 | } 26 | }, 27 | //enable dev source map 28 | devtool: 'eval-source-map', 29 | //enable dev server 30 | devServer: { 31 | historyApiFallback: true, 32 | hot: true, 33 | inline: true, 34 | progress: true, 35 | }, 36 | module: { 37 | preLoaders: [ 38 | { 39 | test: /\.jsx?$/, 40 | include: APP_PATH, 41 | loader: "jshint-loader" 42 | } 43 | ], 44 | loaders: [ 45 | { 46 | test: /\.jsx?$/, 47 | loader: 'babel', 48 | include: APP_PATH, 49 | query: { 50 | presets: ['es2015'] 51 | } 52 | }, 53 | { 54 | test: /\.scss$/, 55 | loaders: ['style', 'css?sourceMap', 'sass?sourceMap'], 56 | include: APP_PATH 57 | }, 58 | { 59 | test: /\.(png|jpg)$/, 60 | loader: 'url?limit=40000' 61 | } 62 | ] 63 | }, 64 | 65 | //custom jshint options 66 | // any jshint option http://www.jshint.com/docs/options/ 67 | jshint: { 68 | "esnext": true 69 | }, 70 | 71 | plugins: [ 72 | new HtmlwebpackPlugin({ 73 | title: 'Hello World app', 74 | template: path.resolve(TEM_PATH, 'index.html'), 75 | filename: 'index.html', 76 | chunks: ['app', 'vendors'], 77 | inject: 'body' 78 | }), 79 | /*new HtmlwebpackPlugin({ 80 | title: 'Hello Mobile app', 81 | template: path.resolve(TEM_PATH, 'mobile.html'), 82 | filename: 'mobile.html' 83 | }),*/ 84 | new webpack.optimize.CommonsChunkPlugin('vendors', 'vendors.js') 85 | //provide $, jQuery and window.jQuery to every script 86 | /*new webpack.ProvidePlugin({ 87 | $: "jquery", 88 | jQuery: "jquery", 89 | "window.jQuery": "jquery" 90 | })*/ 91 | ] 92 | }; 93 | --------------------------------------------------------------------------------