-
Notifications
You must be signed in to change notification settings - Fork 612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stencil 3250 - Webpack 2 w/ Code Splitting, Tree Shaking #964
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/assets/js/bundle.js | ||
webpack.conf.js | ||
/assets/dist | ||
stencil.conf.js | ||
webpack.conf.js |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"parser": "babel-eslint", | ||
"rules": { | ||
"indent": [ | ||
2, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,53 @@ | ||
import 'babel-polyfill'; | ||
__webpack_public_path__ = window.__webpack_public_path__; // eslint-disable-line | ||
|
||
import 'babel-polyfill'; | ||
import $ from 'jquery'; | ||
import account from './theme/account'; | ||
import auth from './theme/auth'; | ||
import blog from './theme/blog'; | ||
import brand from './theme/brand'; | ||
import cart from './theme/cart'; | ||
import category from './theme/category'; | ||
import contactUs from './theme/contact-us'; | ||
import compare from './theme/compare'; | ||
import errors from './theme/errors'; | ||
import errors404 from './theme/404-error'; | ||
import giftCertificate from './theme/gift-certificate'; | ||
import Global from './theme/global'; | ||
import home from './theme/home'; | ||
import orderComplete from './theme/order-complete'; | ||
import rss from './theme/rss'; | ||
import page from './theme/page'; | ||
import product from './theme/product'; | ||
import search from './theme/search'; | ||
import sitemap from './theme/sitemap'; | ||
import subscribe from './theme/subscribe'; | ||
import wishlist from './theme/wishlist'; | ||
|
||
const getAccount = () => import('./theme/account'); | ||
const getLogin = () => import('./theme/auth'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these two functions are shared |
||
const pageClasses = { | ||
'pages/account/orders/all': account, | ||
'pages/account/orders/details': account, | ||
'pages/account/addresses': account, | ||
'pages/account/add-address': account, | ||
'pages/account/add-return': account, | ||
'pages/account/add-wishlist': wishlist, | ||
'pages/account/recent-items': account, | ||
'pages/account/download-item': account, | ||
'pages/account/edit': account, | ||
'pages/account/inbox': account, | ||
'pages/account/return-saved': account, | ||
'pages/account/returns': account, | ||
'pages/auth/login': auth, | ||
'pages/auth/account-created': auth, | ||
'pages/auth/create-account': auth, | ||
'pages/auth/new-password': auth, | ||
'pages/auth/forgot-password': auth, | ||
'pages/blog': blog, | ||
'pages/blog-post': blog, | ||
'pages/brand': brand, | ||
'pages/brands': brand, | ||
'pages/cart': cart, | ||
'pages/category': category, | ||
'pages/compare': compare, | ||
'pages/contact-us': contactUs, | ||
'pages/errors': errors, | ||
'pages/errors/404': errors404, | ||
'pages/gift-certificate/purchase': giftCertificate, | ||
'pages/gift-certificate/balance': giftCertificate, | ||
'pages/gift-certificate/redeem': giftCertificate, | ||
'pages/home': home, | ||
'pages/order-complete': orderComplete, | ||
'pages/page': page, | ||
'pages/product': product, | ||
'pages/amp/product-options': product, | ||
'pages/search': search, | ||
'pages/rss': rss, | ||
'pages/sitemap': sitemap, | ||
'pages/subscribed': subscribe, | ||
'pages/account/wishlist-details': wishlist, | ||
'pages/account/wishlists': wishlist, | ||
'pages/account/orders/all': getAccount, | ||
'pages/account/orders/details': getAccount, | ||
'pages/account/addresses': getAccount, | ||
'pages/account/add-address': getAccount, | ||
'pages/account/add-return': getAccount, | ||
'pages/account/add-wishlist': () => import('./theme/wishlist'), | ||
'pages/account/recent-items': getAccount, | ||
'pages/account/download-item': getAccount, | ||
'pages/account/edit': getAccount, | ||
'pages/account/inbox': getAccount, | ||
'pages/account/return-saved': getAccount, | ||
'pages/account/returns': getAccount, | ||
'pages/auth/login': getLogin, | ||
'pages/auth/account-created': getLogin, | ||
'pages/auth/create-account': getLogin, | ||
'pages/auth/new-password': getLogin, | ||
'pages/auth/forgot-password': getLogin, | ||
'pages/blog': () => import('./theme/blog'), | ||
'pages/blog-post': () => import('./theme/blog'), | ||
'pages/brand': () => import('./theme/brand'), | ||
'pages/brands': () => import('./theme/brand'), | ||
'pages/cart': () => import('./theme/cart'), | ||
'pages/category': () => import('./theme/category'), | ||
'pages/compare': () => import('./theme/compare'), | ||
'pages/contact-us': () => import('./theme/contact-us'), | ||
'pages/errors': () => import('./theme/errors'), | ||
'pages/errors/404': () => import('./theme/404-error'), | ||
'pages/gift-certificate/purchase': () => import('./theme/gift-certificate'), | ||
'pages/gift-certificate/balance': () => import('./theme/gift-certificate'), | ||
'pages/gift-certificate/redeem': () => import('./theme/gift-certificate'), | ||
'pages/home': () => import('./theme/home'), | ||
'pages/order-complete': () => import('./theme/order-complete'), | ||
'pages/page': () => import('./theme/page'), | ||
'pages/product': () => import('./theme/product'), | ||
'pages/amp/product-options': () => import('./theme/product'), | ||
'pages/search': () => import('./theme/search'), | ||
'pages/rss': () => import('./theme/rss'), | ||
'pages/sitemap': () => import('./theme/sitemap'), | ||
'pages/subscribed': () => import('./theme/subscribe'), | ||
'pages/account/wishlist-details': () => import('./theme/wishlist'), | ||
'pages/account/wishlists': () => import('./theme/wishlist'), | ||
}; | ||
|
||
/** | ||
|
@@ -80,11 +63,16 @@ window.stencilBootstrap = function stencilBootstrap(templateFile, contextJSON = | |
|
||
return { | ||
load() { | ||
$(() => { | ||
let pageClass; | ||
$(async () => { | ||
let globalClass; | ||
let pageClass; | ||
let PageClass; | ||
|
||
// Finds the appropriate class from the pageType. | ||
const PageClass = pageClasses[templateFile]; | ||
const pageClassImporter = pageClasses[templateFile]; | ||
if (typeof pageClassImporter === 'function') { | ||
PageClass = (await pageClassImporter()).default; | ||
} | ||
|
||
if (loadGlobal) { | ||
globalClass = new Global(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
> 1% | ||
last 2 versions | ||
Firefox ESR |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,8 +41,16 @@ function development() { | |
function production() { | ||
webpackConfig.watch = false; | ||
webpackConfig.devtool = false; | ||
webpackConfig.plugins.push(new webpack.optimize.DedupePlugin()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
webpackConfig.plugins.push(new webpack.optimize.UglifyJsPlugin({ comments: false })); | ||
webpackConfig.plugins.push(new webpack.LoaderOptionsPlugin({ | ||
minimize: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
})); | ||
webpackConfig.plugins.push(new webpack.optimize.UglifyJsPlugin({ | ||
comments: false, | ||
compress: { | ||
warnings: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
}, | ||
sourceMap: false, // Toggle to turn on source maps. | ||
})); | ||
|
||
webpack(webpackConfig).run(err => { | ||
if (err) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,9 @@ | |
|
||
{{#block "page"}} {{/block}} | ||
|
||
<script src="{{cdn 'assets/dist/theme-bundle.js'}}"></script> | ||
<script>window.__webpack_public_path__ = "{{cdn 'assets/dist/'}}";</script> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is used (in apps.js) to prefix the dynamically loaded chunk requests |
||
<script src="{{cdn 'assets/dist/theme-bundle.main.js'}}"></script> | ||
|
||
<script> | ||
// Exported in app.js | ||
window.stencilBootstrap("{{template_file}}", {{ jsContext }}, false).load(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,73 @@ | ||
var webpack = require('webpack'); | ||
var CleanWebpackPlugin = require('clean-webpack-plugin'), | ||
config = require('./config.json'), | ||
LodashModuleReplacementPlugin = require('lodash-webpack-plugin'), | ||
path = require('path'), | ||
webpack = require('webpack'); | ||
|
||
module.exports = { | ||
watch: false, | ||
devtool: 'source-map', | ||
bail: true, | ||
context: __dirname, | ||
devtool: 'source-map', | ||
entry: { | ||
'theme-bundle': './assets/js/app.js', | ||
}, | ||
output: { | ||
path: `./assets/dist`, | ||
filename: '[name].js', | ||
main: './assets/js/app.js', | ||
}, | ||
bail: true, | ||
module: { | ||
loaders: [ | ||
rules: [ | ||
{ | ||
test: /\.js$/, | ||
loader: 'babel', | ||
include: /(assets\/js|assets\\js|stencil-utils)/, | ||
query: { | ||
compact: false, | ||
cacheDirectory: true, | ||
presets: ['es2015-loose'], | ||
use: { | ||
loader: 'babel-loader', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
options: { | ||
cacheDirectory: true, | ||
compact: true, | ||
minified: true, | ||
plugins: [ | ||
'dynamic-import-webpack', // Needed for dynamic imports. | ||
'lodash', // Automagically tree-shakes lodash. | ||
'transform-regenerator', // Transforms async and generator functions. | ||
], | ||
presets: [ | ||
['env', { | ||
loose: true, // Enable "loose" transformations for any plugins in this preset that allow them. | ||
modules: false, // Don't transform modules; needed for tree-shaking. | ||
useBuiltIns: true, // Tree-shake babel-polyfill. | ||
}], | ||
], | ||
} | ||
} | ||
} | ||
] | ||
], | ||
}, | ||
output: { | ||
chunkFilename: 'theme-bundle.chunk.[name].js', | ||
filename: 'theme-bundle.[name].js', | ||
path: path.resolve(__dirname, "assets/dist"), | ||
}, | ||
plugins: [ | ||
new CleanWebpackPlugin(['assets/dist'], { | ||
verbose: true, | ||
watch: false, | ||
}), | ||
new webpack.LoaderOptionsPlugin({ | ||
minimize: true, | ||
}), | ||
new LodashModuleReplacementPlugin, // Complements 'babel-plugin-lodash by shrinking it's cherry-picked builds further. | ||
new webpack.ProvidePlugin({ | ||
$: 'jquery', | ||
jQuery: 'jquery', | ||
'window.jQuery': 'jquery', | ||
}) | ||
}), | ||
new webpack.optimize.CommonsChunkPlugin({ | ||
children: true, | ||
minChunks: 2, | ||
}), | ||
], | ||
resolve: { | ||
alias: { | ||
jquery: path.resolve(__dirname, 'node_modules/jquery/dist/jquery.min.js'), | ||
jstree: path.resolve(__dirname, 'node_modules/jstree/dist/jstree.min.js'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. both package.json's for jquery and jstree point to the their non-minified versions, this resolves to the minified versions instead |
||
}, | ||
}, | ||
watch: false, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this sets the public path for webpack to the base path for the cdn