Skip to content

Commit

Permalink
Add nunjucks loader to webpack
Browse files Browse the repository at this point in the history
This allows us to require nunjucks views from JS code
  • Loading branch information
ediblecode committed May 24, 2017
1 parent 7f831e1 commit 61c1a3b
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 63 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"moment": "^2.15.1",
"node-common-errors": "^0.4.0",
"nunjucks": "^3.0.0",
"nunjucks-loader": "^2.4.8",
"pixrem": "^3.0.2",
"postcss-banner": "^3.0.0",
"serve-favicon": "^2.4.2",
Expand Down
128 changes: 65 additions & 63 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,67 +78,69 @@ const minPlugins = [
bannerPlugin
];

const normalModule = {
loaders: [{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: "babel-loader",
query: {
babelrc: false,
presets: [ "es2015" ],
passPerPreset: true,
plugins: [
["typecheck", {
disable: { production: true }
}],
"syntax-flow",
"transform-flow-strip-types"
]
}
}]
};

const oldIEModule = {
loaders: [{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: "babel-loader",
query: {
babelrc: false,
presets: [ "es2015" ],
passPerPreset: true,
plugins: [
["typecheck", {
disable: { production: true }
}],
"syntax-flow",
"transform-flow-strip-types",
"transform-es3-member-expression-literals",
"transform-es3-property-literals"
]
const moduleObj = {
loaders: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: "babel-loader",
query: {
babelrc: false,
presets: [ "es2015" ],
passPerPreset: true,
plugins: [
["typecheck", {
disable: { production: true }
}],
"syntax-flow",
"transform-flow-strip-types",
"transform-es3-member-expression-literals",
"transform-es3-property-literals"
]
}
},
{
test: /\.(njk|nunjucks)$/,
loader: "nunjucks-loader"
}
}],
// Fix for IE8 to wrap default keyword in quotes
// See https://github.com/reactjs/react-redux/issues/232#issuecomment-167665147
postLoaders: [{
test: /\.js$/,
loader: StringReplacePlugin.replace({
replacements: [
{
pattern: /\.default(?=[^\w$])/g,
replacement: function () {
return "['default']";
}
},
{
pattern: /\{\sdefault:/g,
replacement: function () {
return "{ 'default':";
],
postLoaders: [
{
test: /\.js$/,
loader: StringReplacePlugin.replace({
replacements: [
// Fix for IE8 to wrap default keyword in quotes
// See https://github.com/reactjs/react-redux/issues/232#issuecomment-167665147
{
pattern: /\.default(?=[^\w$])/g,
replacement: function () {
return "['default']";
}
},
{
pattern: /\{\sdefault:/g,
replacement: function () {
return "{ 'default':";
}
},
// Fix for "Uncaught TypeError: Cannot read property 'MutationObserver' of undefined" win nunjucks
// See https://github.com/mozilla/nunjucks/issues/520
{
pattern: /global\.MutationObserver/g,
replacement: function () {
return "window.MutationObserver";
}
},
{
pattern: /global\.WebKitMutationObserver/g,
replacement: function () {
return "window.WebKitMutationObserver";
}
}
}
]
})
}]
]
})
}
]
};


Expand All @@ -151,7 +153,7 @@ module.exports = [
filename: "experience.dev.js",
sourceMapFilename: "experience.dev.map"
},
module: normalModule,
module: moduleObj,
plugins: normalPlugins
}),

Expand All @@ -162,7 +164,7 @@ module.exports = [
filename: "experience.min.js",
sourceMapFilename: "experience.min.map"
},
module: normalModule,
module: moduleObj,
plugins: minPlugins
}),

Expand All @@ -175,7 +177,7 @@ module.exports = [
filename: "experience.oldie.dev.js",
sourceMapFilename: "experience.oldie.dev.map"
},
module: oldIEModule,
module: moduleObj,
plugins: normalPlugins
}),

Expand All @@ -187,7 +189,7 @@ module.exports = [
filename: "experience.oldie.min.js",
sourceMapFilename: "experience.oldie.min.map"
},
module: oldIEModule,
module: moduleObj,
plugins: minPlugins
})
];

0 comments on commit 61c1a3b

Please sign in to comment.